#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/