case 1:
{
insert_menu();
donor[turn].inputData();
::turn++; //accessing global variable
char c = '\0';
while (c != '0') {
cout << "Press 1 to save, 0 to not save: ";
cin >> c;
fflush(stdin);
if (c == '1') {
cout << "Record saved successfully.";
cout << "\nWant to insert another record? [y/n]: ";
char op = '\0';
cin >> op;
//fflush(stdin);
if (op = 'y') {
cout << "Enter another record\n\n";
donor[::turn].inputData();
cout << "Record entered successfully\n";
::turn++; //increment to global variable turn
} //end scope of nested if
else {
cout << "Press Enter to return to main menu";
//fflush(stdin);
// getchar();
break;
} //end scope of nested if
} //end scope of first if
else {
::turn--;
cout << "Record not saved! You are being redirected to Main Menu" << endl;
system("pause");
//break;
}
} //end scope of while
} // end scope of case 1
break; //exiting case 1
我不知道爲什麼,當我嘗試輸入嵌套,否則它跳過它,無論我按y或n,它是給出選項在兩種情況下輸入輸入。有什麼問題?爲什麼嵌套if語句不工作?
請格式化代碼,並要求實際問題 –
我們需要一個可讀[MCVE(http://stackoverflow.com/help/mcve)和明確的問題陳述能夠理解這個問題。 –
'if(op ='y'){'是一項任務。它總是如此,並設置爲'y'。 – drescherjm