無論我輸入什麼,在此函數中唯一識別的int是1. 如果選擇了其他任何內容,則重複執行do-while循環。該代碼在沒有任何OR操作符的情況下也工作正常,例如, 「而(輸入!= 0)」只識別int輸入爲1
void menu()
{
int input = -1;
do
{
cout << " ---------------" << endl << " - OU6 -" << endl << " ---------------" << endl;
cout << "1. Read a transaction from the keyboard." << endl;
cout << "2. Print all transactions to console." << endl;
cout << "3. Calculate the total cost." << endl;
cout << "4. Get debt of a single person." << endl;
cout << "5. Get unreliable gold of a single person." << endl;
cout << "6. List all persons and fix." << endl;
cout << "0. Save and quit application." << endl;
cin >> input;
} while (input != (0 || 1 || 2 || 3 || 4 || 5 || 6));
if (input == 0)
{
cout << "0!" << endl;
cin.get();
}
if (input == 1)
{
cout << "1!" << endl;
cin.get();
}
if (input == 2)
{
cout << "2!" << endl;
cin.get();
}
}
我喜歡關於測試爲何做什麼它做額外的細節。 – Almo