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') {' является присвоением. он всегда верен и устанавливает op в 'y'. – drescherjm