while loop stops working after second user input C++ -
i trying implement feature program says "do want quit?" if 'y or 'y' exit program. if 'n' or 'n' rerun menu , let user whatever want.
the issue facing menu runs first time , user can yes or no. second time can yes or no. third time when reaches while loop infinitely outputs menu.
can please advise?
the code menu
char exitinput = null; char y = 'y', y = 'y', n = 'n', n = 'n'; while (exitinput != y || exitinput != y || exitinput == n || exitinput == n) { cout << "*\t please choose 1 of following options. \t *" << endl; cout << "1. \t" << "transfer amount \n" << "2. \t" << "list recent transactions \n" << "3. \t" << "display account details , current balance \n" << "4. \t" << "quit \n"; int menuselection; cout << "enter option here: "; cin >> menuselection; switch (menuselection) { case 1: ....... case 2: cout << "do want exit application? "; cin >> exitinput; } }
this condition
while (exitinput != y || exitinput != y || exitinput == n || exitinput == n)
will true. have change like:
while (exitinput != y && exitinput != y)
also, initial value of exitinput
not make sense, put char exitinput = 'n'
Comments
Post a Comment