您好,我试图了解为什么如果输入9或更高的分数来判断是否通过,但是它不会导致if表示> = 4和
谢谢
while(!(judge >= 4) && (judge <= 8))
{
printf("How many judges are there ? Enter a number between 4 - 8 \n");
scanf("%d", &judge);
while(!(judge >= 4) && (judge <= 8))
{
printf("You entered %d Enter a number between 4 - 8 \n", judge);
scanf("%d", &judge);
if((judge >= 4) && (judge <= 8))
{
break;
}
}
}
最佳答案
好像您在中缺少一对括号
while(!((judge >= 4) && (judge <= 8)))
^ ^
(此错误出现在两个地方。)
顺便说一句,您可以通过重构代码来避免很多重复:
printf("How many judges are there ? Enter a number between 4 - 8 \n");
for (;;) {
scanf("%d", &judge);
if (judge >= 4 && judge <= 8) {
break;
}
printf("You entered %d Enter a number between 4 - 8 \n", judge);
}