c - 我在 do/while 循环中有一段时间,但它仍然告诉我我没有

标签 c do-while cs50

这是我的代码

#include <stdio.h>
#include <cs50.h>
int main(void)
{
    int n=0;
    do 
        printf("Height of Pyramid:\n");
        n = GetInt();
    while (n>=0);
    printf("you picked %i", n);
}

这是我的错误

mario.c:8:9: error: expected 'while' in do/while loop
        n = GetInt();
        ^
mario.c:6:5: note: to match this 'do'
    do 
    ^

最佳答案

您忘记包含大括号 {...} 。替换为:

do {
    printf("Height of Pyramid:\n");
    n = GetInt();
} while (n>=0);

关于c - 我在 do/while 循环中有一段时间,但它仍然告诉我我没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25171936/

相关文章:

我不能无限期地使用 fscanf() 吗?

c - 如何在另一个子字符串中找到多次出现的子字符串并执行 'some' 操作?

c - 如何修复 - 使用 getchar() 和 do-while 的意外输出

c - 修改有缓冲区溢出漏洞的C代码跳过代码

C 检测文件末尾的最后一个新行

c - 'C' 中变量和指针的字符串连接

c - 为什么此代码会从 'char *' 错误分配到 'char'?

c - 仅在 C 中验证字母输入

Java:如何询问用户是否想再玩一次

java - 如何重新启动 while 循环以重新启动游戏?