I have a switch statement and I want to continue until I choose 9 for exit, but if I enter an invalid choose on want to prompt the user. The problem is when I prompt the user I don't pause for input I just exit the loop. Is this because cin has to be flushed or shoudl I you C scanf?
do
{
choose = Display_Menu();
switch (choose)
{
case 1:
CD_Dbase.Reset_Everything();
break;
case 2:
CD_Dbase.oldfile = 1;
CD_Dbase.Open_File();
break;
case 3:
/*read_string("Enter the file name: ", fname, FNAME_SIZE);*/
CD_Dbase.File_Save();
break;
case 4:
/*read_string("Enter the file name: ", fname, FNAME_SIZE);*/
CD_Dbase.File_Save_As();
break;
case 5:
/*read_string("Enter the file name: ", fname, FNAME_SIZE);*/
CD_Dbase.File_Append();
break;
case 6:
CD_Dbase.changes = 1;
CD_Dbase.Add_Record();
break;
case 7:
CD_Dbase.Display_One_Cd();
break;
case 8:
CD_Dbase.Display_All();
break;
case 9:
CD_Dbase.Quit();
exit(1);
break;
default:
cout << "Please enter a valid choice? " << endl;
cin >> choose;
}/* end swithc */
/*break; */
}while (choose < 9);/* end while*/
You need to cin the choice.
After you get the input, use the switch statement.
Also,you don't really need the while condition at the end..the switch takes care of all the possible cases along with the default.