为什么我的for循环期望显示标识符错误?

时间:2018-06-15 13:41:02

标签: c compiler-errors cs50

#include <cs50.h>
#include <stdio.h>

int main(void)
{
//Prompt user for valid input
int n;
do
{
    n = get_int("height: ");
}
while (n < 0 || n > 23);
}
//drawing pyramid
for(int i = 0; i < n; i++)
{
printf(" ")
}

当我进入make mario时,我的终端会发生以下情况......

error: expected identifier or '(' 
for (int i = 0; i < n; i++)
^  

有人知道我的代码中出现此错误消息的原因吗?为什么这会被标记? “for”错误下方的绿色(^)箭头是否意味着程序不希望我使用for循环?

2 个答案:

答案 0 :(得分:0)

您使用逗号“,”而不是冒号“;”。

在for循环中,使用冒号“;”来划分单独的声明。

答案 1 :(得分:0)

while (n < 0 || n > 23);
}

你还有一个额外的}。删除它,你的代码应该编译。每个开口{只需要一次关闭}。

还要考虑正确的缩进。这有助于你看到这样的错误。