在我的代碼中,即使輸入'Q'或'q',程序仍然會循環顯示菜單。這裏有什麼問題?下面是代碼:C++菜單中的循環
{
char selection;
do {
cout << "Add a county election file A" << endl;
cout << "Show election totals on screen P" << endl;
cout << "Search for county results S" << endl;
cout << "Exit the program Q" << endl;
cout << "Please enter your choice: ";
cin >> selection;
} while ((selection != 'Q' || selection != 'q'));
return 0;
}
如果輸入'q','selection!='Q''爲true。如果你輸入'Q',另一個是真的......所以沒有辦法離開這個循環。 – Mat
你是第一次說話嗎? –
經典錯誤'選擇!='Q'||選擇!='q''應該是'選擇!='Q'&&選擇!='q'' – john