Hey can anyone see what wrong with my menu in the while loop it keeps printing out dixie if i press 1 in an unlimited loop. I have a while loop around the menu so that the menu is always there for the user to go back through choices.
here is my code:
#include <iostream>
using namespace std;
int main()
{
int choice;
bool menu = true;
cout <<"========Welcome to the database menu========\n";
cout << "Press 1 to insert a new record at a particular position\n"
"Press 2 to delete a record from a particular position\n"
"Press 3 to search the database and print results\n"
"Press 5 to find the average experience points of players at a particular level\n"
"Press 6 to find and remove all duplicate entries\n"
"Press 0 to quit\n\n\n\n\n\n\n\n\n";
cout << "Choice: ";
cin >> choice;
//*****************************************************************************
// Switch menu to display the menu.
//*****************************************************************************
while(menu)
{
switch (choice)
{
case 1:
cout << "dixie";
break;
case 2:
cout << "bexie";
break;
default:
cout<< "That is not a choice!!!\n";
}
}
getchar();
getchar();
}
It says
while (menu)and that means it’ll keep doing that until you set menu tofalse.Also, I think you want to add the
cin >> choicein the loop, or it’ll just repeat the selection again and again.