-2
我正在做一個學校項目,要求我在每個選項後返回到菜單,但我目前遇到使用do-while循環返回菜單的麻煩,因爲我的while(true)由於(真)未定義而導致運行問題。請幫忙!我的while循環不起作用
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);
這是爲什麼?
嘗試'while(1)'。 – ForceBru
'while while(1)'或'#include'。 –
randomir
謝謝while(1)works! :) – Danzel