k = 0;
while (k == 0){
printf ("enter a value between 0 - 80\n");
scanf ("%d", &coldest);
if(coldest <= 80 && coldest >= 0){
k = 1;
}
else
k = 0;
}
printf ("this number ---->%d<-----\n", coldest);
这是我写的,当您输入参数 0-80 之外的任何内容时,它应该循环并再次询问用户,但我遇到一个问题,它将跳过 scanf
然后继续弹出 printf
。
编辑:≤ 到 <= 和 ≥ 到 >= -Edit2:80 <=最冷到最冷<= 80
最佳答案
if
条件测试
is coldest >= 80
AND
is coldest >= 0
你现在能发现错误吗?
此外,不测试 scanf
的返回值始终是一个错误。
关于c - Scanf 函数不会循环我的 while 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48974694/