c - do while 循环中未声明的标识符,C

标签 c do-while cs50 undeclared-identifier

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

int main(void)
{
    do
    {
        //ask for input with 1-8
        int height = get_int("Height: ");
    }
    while (height > 0);
}

我得到了错误代码:使用未声明的标识符“height”(在 while 语句中) 我对编程完全陌生,我不知道如何解决这个问题。有人可以帮忙吗?

最佳答案

变量height范围do..while循环的主体。此循环的条件位于循环体之外,因此 height 不在循环条件的范围内。

height的定义移到循环之外。

int height;
do
{
    //ask for input with 1-8
    height = get_int("Height: ");
}
while (height > 0);

关于c - do while 循环中未声明的标识符,C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70725850/

相关文章:

C匹配算法(使用递归+排列)

python - 一些很好的教程来介绍我自己进入 Telepathy API?

c - C 中的 double 等于 0 问题

c - 打印 strtok 结果后 vprintf() 中的 SIGSEGV

c - c 中的循环产生不需要的结果

java - do while 循环..如果给出正确的输入则继续

c++ - 为什么我的 do while 循环中会得到一个额外的字符?

c - "not all control paths return a value”在这个程序中意味着什么?

c - 为什么我的 while 循环不在 C 中重复?

CS50x pset3(为什么我的程序没有通过Check50?)