Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Use the switch and do while statements to write a program that displays the following menu:
---------------------------- Menu -------------------------
1.Option 1 
2.Option 2 
3.Option 3 
4.Option 4 
5.Help
6.Quit
----------------------------------------------------------- 
Please Enter You Choice (1-6):

 If the user enters a choice between 1-5, the program displays message stating the
option picked by the user. The menu is displayed again.  If the user enters 6 as choice, the program displays “Thank you for choosing our program” and ends.
 If the user enters a choice other than 1-6, the program displays “Invalid choice. You need to select an option between 1 and 6”. The menu is displayed again.

PLEASE HELP ME TO FINISH THIS CODE
THANK YOU


C++
#include <iostream>

using namespace std;

int main() {

	int Number;
	int Menu;
	cout << "----------------menu------------------" << endl;
	cout << " 1.Option 1 " << endl;
	cout << " 2.Option 2 " << endl;
	cout << " 3.Option 2 " << endl;
	cout << " 4.Option 4 " << endl;
	cout << " 5.Help " << endl;
	cout << " 6.Quit " << endl;
	cout << "---------------------------------------" << endl;
	cout << " Please Enter You Choice (1-6): ";
	cin >>Number;
	switch (Number)
	{
	case 1 :
	case 2:
	case 3:
	case 4:
	case 5:
		break;
	case 6:
		cout << "Thank you for choosing our program " << endl;
		break;
	default:
		cout << "Invalid choice. You need to select an option between 1 and 6" << endl;
		break;
	}

	system("pause");
    return 0;
}
Posted
Updated 31-Oct-15 21:48pm
v3
Comments
[no name] 31-Oct-15 17:24pm    
You are near to the solution, where is the Problem?
Initalize Number at the beginning and write this "while (Number != 6)" and some break for the cases.
Assam ALzookery 31-Oct-15 17:28pm    
i don't know how to display the menu again when the user chose number between 1-5
[no name] 31-Oct-15 17:37pm    
This is your choice, "where" you place the "while".
Number= -1;
while(Number != 6)
{
// Here your code
cout << "----------------menu------------------" << endl;
// .....all the rest what you showed in your question....
}
Assam ALzookery 31-Oct-15 17:39pm    
Thank you for your help , but its required to use the do while statement
[no name] 31-Oct-15 17:41pm    
do{
// .....do it
}while(Number != 6);

1 solution

C++
#include <iostream>

using namespace std;

int main() {

	int Number;
	int Menu;
	cout << "----------------menu------------------" << endl;
	cout << " 1.Option 1 " << endl;
	cout << " 2.Option 2 " << endl;
	cout << " 3.Option 2 " << endl;
	cout << " 4.Option 4 " << endl;
	cout << " 5.Help " << endl;
	cout << " 6.Quit " << endl;
	cout << "---------------------------------------" << endl;

	do {

		cout << " Please Enter You Choice (1-6): ";
		cin >> Number;
		switch (Number)
		{
		case 1: 
			cout << "You chose option 1 " << endl;
			cout << "----------------menu------------------" << endl;
			cout << " 1.Option 1 " << endl;
			cout << " 2.Option 2 " << endl;
			cout << " 3.Option 2 " << endl;
			cout << " 4.Option 4 " << endl;
			cout << " 5.Help " << endl;
			cout << " 6.Quit " << endl;
			cout << "---------------------------------------" << endl;
			break;
		case 2:	cout << "You chose option 2 " << endl;
			cout << "----------------menu------------------" << endl;
			cout << " 1.Option 1 " << endl;
			cout << " 2.Option 2 " << endl;
			cout << " 3.Option 2 " << endl;
			cout << " 4.Option 4 " << endl;
			cout << " 5.Help " << endl;
			cout << " 6.Quit " << endl;
			cout << "---------------------------------------" << endl;
			break;

		case 3:
			cout << "You chose option 3 " << endl;
			cout << "----------------menu------------------" << endl;
			cout << " 1.Option 1 " << endl;
			cout << " 2.Option 2 " << endl;
			cout << " 3.Option 2 " << endl;
			cout << " 4.Option 4 " << endl;
			cout << " 5.Help " << endl;
			cout << " 6.Quit " << endl;
			cout << "---------------------------------------" << endl;
			break;
		case 4:
			cout << "You chose option 4 " << endl;
			cout << "----------------menu------------------" << endl;
			cout << " 1.Option 1 " << endl;
			cout << " 2.Option 2 " << endl;
			cout << " 3.Option 2 " << endl;
			cout << " 4.Option 4 " << endl;
			cout << " 5.Help " << endl;
			cout << " 6.Quit " << endl;
			cout << "---------------------------------------" << endl;
			break;
		case 5:
			cout << "You chose option 5 " << endl;
			cout << "----------------menu------------------" << endl;
			cout << " 1.Option 1 " << endl;
			cout << " 2.Option 2 " << endl;
			cout << " 3.Option 2 " << endl;
			cout << " 4.Option 4 " << endl;
			cout << " 5.Help " << endl;
			cout << " 6.Quit " << endl;
			cout << "---------------------------------------" << endl;
			break;
			break;
		case 6:
			cout << "Thank you for choosing our program " << endl;
	
			break;
		default:
			cout << "Invalid choice. You need to select an option between 1 and 6" << endl;			cout << "----------------menu------------------" << endl;
			cout << " 1.Option 1 " << endl;
			cout << " 2.Option 2 " << endl;
			cout << " 3.Option 2 " << endl;
			cout << " 4.Option 4 " << endl;
			cout << " 5.Help " << endl;
			cout << " 6.Quit " << endl;
			cout << "---------------------------------------" << endl;
			break;
		}
	} while (Number!= 6);
	system("pause");
    return 0;
}
</iostream>
 
Share this answer
 
Comments
George Jonsson 1-Nov-15 22:03pm    
Why do you repeat the code for the menu in all cases?
Don't you think it would be smarter to put that code in one place?
And please format your code so it is readable.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900