Click here to Skip to main content
14,265,982 members
Rate this:
Please Sign up or sign in to vote.
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


#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
0x01AA 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
0x01AA 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
0x01AA 31-Oct-15 17:41pm
   
do {
// .....do it
}while(Number != 6);
Assam ALzookery 31-Oct-15 17:45pm
   
Than you and God bless You
If you have the time please try to help me out with my other question

http://www.codeproject.com/Questions/1045583/Write-a-program-that-prompts-the-user-for-a-collec?arn=0
0x01AA 31-Oct-15 17:58pm
   
You are welcome. I will try to help on the other question, but I expect your help also. Means I do not deliver "the" solution but I will give you some hints.
Assam ALzookery 31-Oct-15 18:25pm
   
absolutely, Thank you Again
Assam ALzookery 1-Nov-15 15:30pm
   
Thank you , I have already answer the question for this one
OriginalGriff 1-Nov-15 2:57am
   
I suggest you post this as the solution, with the users comments.
BillWoodruff 31-Oct-15 18:47pm
   
If this is not a C# question, please remove that tag.
Sergey Alexandrovich Kryukov 31-Oct-15 21:38pm
   
The question makes no sense. "do... while" is one thing, "switch" is another one. Use whatever you want. And your code makes no practical sense due its quality. Try to use some logic and learn the syntax and associated semantic. Show something which can be a starting point and then ask your question.
—SA

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

#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>
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100