In my code there is a problem where even when I enter ‘Q’ or ‘q’ the program keeps looping the menu. What’s wrong here? Here is the code:
{
char selection;
do {
cout << "Add a county election file A" << endl;
cout << "Show election totals on screen P" << endl;
cout << "Search for county results S" << endl;
cout << "Exit the program Q" << endl;
cout << "Please enter your choice: ";
cin >> selection;
} while ((selection != 'Q' || selection != 'q'));
return 0;
}
You want to use the And (
&&) operator in your test, not the Or (||) operator. Otherwise, one ofselection != 'Q'andselection != 'q'will always be true, and your loop will never exit.