我正在做一个学校项目,要求我在每个选项后返回到菜单,但我目前在使用 do-while 循环返回菜单时遇到问题,因为我的 while(true) 因运行而出现问题(true) 未定义。请帮忙!
do {
// print out menu
printf("================================== MENU ==================================== \n");
printf("HELLO PLEASE CHOOSE 1 OPTION BELOW: \n");
printf("(1) CO2 reading and health advisory descriptor of a given classroom and time \n");
printf("(2) 3 hourly average CO2 reading for a selected classroom \n");
printf("(3) Highest CO2 reading from the classroom for a selected time \n");
printf("(4) Top 3 unhealthy readings for a selected classroom \n");
printf("(5) List of time periods and classroom with above 'Average' value \n");
printf("(6) The unhealthiest classroom CO2 reading from 7am to 11am \n");
printf("============================================================================ \n");
printf("\n");
// getting user input
printf("Please enter your option: ");
int userInput;
scanf_s("%d", &userInput); // put the user input into int userInput
printf("\n");
// check for the user input and run the function accordingly
switch (userInput)
{
case 1: // if the user press 1
{
// call option1 function
option1();
break;
}
case 2:
{
// call option2 function
option2();
break;
}
case 3:
{
// call option3 function
option3();
break;
}
case 4:
{
// call option4 function
option4();
break;
}
case 5:
{
// call option5 function
option5();
break;
}
case 6:
{
// call option6 function
option6();
break;
}
}
} while (true);
为什么会这样呢?
最佳答案
只需包含 <stdbool.h>
使用 true 和 false bool 变量。
检查this了解更多详情。
关于c - 我的 while 循环不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45534396/