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