0
在試用此程序的這一部分時,我得到了Xcode中的「代碼將永遠不會執行」警告。該警告出現在do while循環的while部分的條件中。如果列表中顯示的其中一個數字沒有輸入,應打印下面的字符串。有什麼建議麼?在執行循環條件時出錯C
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int input;
do
{
printf("Welcome to the Arithmetic Quiz Program!\n\n
Please choose one of the following by entering the correspoding number:\n\n
1. Give me an addition problem.\n
2. Give me a subtraction problem.\n
3. Give me a multiplication problem.\n
4. Quit.\n\n");
scanf(" %i", &input);
} while (input!=1 || input!=2 || input!=3 || input!=4);
return 0;
}
使用'在while循環中&&'而不是'||'。 – Himanshu
'input!= 1 ||輸入!= 2 ||輸入!= 3 ||輸入!= 4'永遠不會是錯誤的。要明白爲什麼,請嘗試在您的腦海中進行評估。 – immibis
do-while循環至少執行一次。 – XDProgrammer