I am creating a library management system. I have a few menus for which the user can select an option but when the wrong option is chosen it should display an error message and ask the user to select another option. Currently after the user selects an option which is not available, the program exits.
while(1)
{
int mainSelect;
int studentOption;
int dvdOption;
int bookOption;
char name[30];
// Ask the user to select an option
cout << "****************************************************" << endl;
cout << "******************* Main Menu ********************" << endl;
cout << "****************************************************" << endl;
cout << "* *" << endl;
cout << "* PROGRAM DESCRIPTION *" << endl;
cout << "* ------------------------------------------------ *" << endl;
cout << "* *" << endl;
cout << "* 1 DVD *" << endl;
cout << "* *" << endl;
cout << "* 2 Books *" << endl;
cout << "* *" << endl;
cout << "* 3 Students *" << endl;
cout << "* *" << endl;
cout << "* 4 EXIT *" << endl;
cout << "* *" << endl;
cout << "* ------------------------------------------------ *" << endl;
cout << "* *" << endl;
cout << "****************************************************" << endl;
// Read user selection
cin.getline( name, 80);
mainSelect = name[0];
// Switch statement to select between the options
switch (mainSelect)
{
case'1':
break;
case'2':
break;
case'3':
break;
case'4':
break;
case'5':
exit(0);
break;
case'6':
cout << "Invalid selection!" << endl;
break;
default:
cout<<"Incorrect selection. Please select from the given options." <<endl;
}
Also I have several options such as Add a new book, delete a book. When the user selects add a new book option and after adding a book the program exits. How I can make it after the user adds a book the system goes back to the menu.
This is some of my code showing the switch case for the Book menu: