In C++ your job is to complete the listing of the main menu and three sub menus
ID: 3596057 • Letter: I
Question
In C++ your job is to complete the listing of the main menu and three sub menus. More clearly, you will write loops and show the main menu to the user when the program first starts and then allow the user to make a choice to go to the selected sub menu.
1. The user should be able to make a selection to go back to the main menu when selecting "Go back to main menu" option from a sub menu.
2. The only way for the user to exit the program is to select "Exit" menu item in the main menu.
sample run
Main Menu:
1. Department Menu
2. Staff Menu
3. Patient Menu
4. Exit the program
Enter a choice (1-4):
4 Thank you for using my program
Press any key to continue . . .
3. If the user selects "Add" , "List", etc. menu items in a sub menu, your program will do nothing for now. Later, you will modify your code to actually do the selected task.
Explanation / Answer
Implemented the code as per the requirement, but the options which are to be there in sub menu are not clear so left that part as mentioned in the question.
Code:
---------------
#include <iostream>
using namespace std;
int main() {
int x=0;
//Runnigng infinite loop till the user select the exit option
while(true){
// Displaying the menu
cout<<"Main Menu: 1. Department Menu 2. Staff Menu 3. Patient Menu 4. Exit the program Enter a choice (1-4): ";
//Taking user input
cin >> x;
//If conditions for different menu
if(x==1){
cout<<"Department Menu: 1.Go back to main menu ";
cin>>x;
if(x==1){
continue;
}
else{
cout<<"Enter valid input ";
}
}
else if(x==2){
cout<<"Staff Menu: 1.Go back to main menu ";
cin>>x;
if(x==1){
continue;
}
else{
cout<<"Enter valid input ";
}
}
else if(x==3){
cout<<"Patient Menu: 1.Go back to main menu ";
cin>>x;
if(x==1){
continue;
}
else{
cout<<"Enter valid input ";
}
}
//Exit condition
else if(x==4){
cout<<"Thank you for using my program ";
exit(0);
}
}
}