int towerh;
do{
printf ("give me an integer between 1 and 23 and I will make a tower");
int towerh = GetInt();
}while (towerh < 1 || towerh > 23);
只要 towerh
不在 1 和 23 之间,我就尝试使此代码块循环。我不断收到错误消息,指出该变量需要初始化。
我确信这是一件小事,但我不知道如何在 C 中评估或纠正它。
最佳答案
只需将 int towerh;
更改为 int towerh = 0;
。这就是所谓的初始化变量,通常 C 编译器讨厌你错过它。
此外,您在循环中一次又一次地创建 towerh
,我建议使用 scanf
而不是未提及的 GetInt
,这样您可以结束于:
int towerh = 0;
do {
printf("Give me an integer between 1 and 23 and I will make a tower: ");
scanf("%d", &towerh);
} while (towerh < 1 || towerh > 23);
关于c - 使用 while 循环输入时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41317766/