我目前正在做计算机科学的CS50入门:我开始编写这段代码(用C编写),我必须根据用户编写的内容对金字塔进行编码。
这里是我的代码:
#include <stdio.h>
#include <cs50.h>
int main(void);
int n;
do
{
n = get_int("Positive Number: \n");
}
while (n > 0 || n < 9);这里是我的终端显示的错误:
mario.c:6:1: error:预期标识符或‘'(’do ^ mario.c:10:1: error:预期标识符或‘’( while (n >0 x\n<9));^2生成错误。目标“mario”失败的配方:*mario错误1
有人能帮忙吗?威廉
发布于 2020-08-18 16:06:36
在函数main声明后放置分号。
int main(void);
^^^^拆下它,把主阀体密封在支架上。
int main(void)
{
//...
}同时,这似乎也是do-while语句的条件。
do
{
n = get_int("Positive Number: \n");
}
while (n > 0 || n < 9);是不正确的。如果输入的n值不是正的,或者大于或等于9,那么我怀疑您希望重复这个循环。在这种情况下,情况应该类似于
do
{
n = get_int("Positive Number: \n");
} while ( !( n > 0 && n < 9 ) );发布于 2020-08-18 15:20:15
看看你的main()。您不是在编写定义,而是声明主函数原型。通过添加大括号来修复它:
int main(void) {
.
.
.
return 0;
}发布于 2020-08-18 15:45:18
您必须对main()函数进行编码。
https://stackoverflow.com/questions/63471686
复制相似问题