can anyone please solve this problem

Using Nested Switch statement, write a program that displays the following menu for the food items available to take order from the customer:
• B= Burger
• F= French Fries
• P= Pizza
• S= Sandwiches
After taking inputs for food item your program will ask four different categories for each food item for example if user press B for Burger it will display following menu:
• Burger 1 Rs. 200 = 1
• Burger 2 Rs. 250 = 2
• Burger 3 Rs. 300 = 3
• Burger 4 Rs. 350 = 4
Similar menu will be open for other food Items. After taking inputs the food items and food category your program will ask quantity of food item for a particular category required. For example, if user press B for Burger 1 it will display following menu:
• For 1 Burger = A
• For 2 Burgers = B
• For 4 Burgers = C
Similar menu will be open for other food Categories. After taking all inputs from user your program must calculate appropriate bill for a user. For example, if user enters B for Food Item 2 for food category and C for 4 burgers it will displays bill as:
Your total bill is = 1400 RS
Last edited on
Hello shaheer,

Looks like fun.

What have you done?

As keskiverto once said:

Please note that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.

Or say that you do not understand the instructions or how to figure them out.

Andy
#include <iostream>
using namespace std;
int main()
{

char ch1;
cout<<"please select the food item\nB= Burger\nF= French Fries\n P= Pizza\nS= Sandwiches \n";
cin>>ch1;
switch (ch1)
{
case 'B':
cout<<" Burger 1 Rs. 200 = 1 \n Burger 2 Rs. 250 = 2 \n Burger 3 Rs. 300 = 3 \n Burger 4 Rs. 350 = 4 ";
cin<<t;

switch(ch2)
case '1' :
cout<<"yo"

break;
case 'F':
cout<<" French Fries 1 Rs. 200 = 1 \n French Fries 2 Rs. 250 = 2 \n French Fries 3 Rs. 300 = 3 \n French Fries 4 Rs. 350 = 4 ";
break;
case 'P':
cout<<"Pizza 1 Rs. 200 = 1 \n Pizza 2 Rs. 250 = 2 \n Pizza 3 Rs. 300 = 3 \n Pizza 4 Rs. 350 = 4";
break;
case 'S':
cout<<"Sandwiches 1 Rs. 200 = 1 \n Sandwiches 2 Rs. 250 = 2 \n Sandwiches 3 Rs. 300 = 3 \n Sandwiches 4 Rs. 350 = 4";
break;
}
}





I have written this code so far
Hello shaheer,

PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

It makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.

This is my first attempt. I worked with what you started with and made it work. I had t make some changes to get it to compile. See the comments in the code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <cctype>  /<--- For std::tolower() and std::toupper().
#include <limits>  // <--- Added for the last lines just above return. You may not need as I do.

using namespace std;  // <--- Best not to use.

int main()
{
	char ch1{};  // <--- Could use a better name like "input". Makes the program easier to follow.

        // <--- Changed next line for better appearance in output.
	cout << "please select the food item\n B = Burger\n F = French Fries\n P = Pizza\n S = Sandwiches\n Enter Choice: ";
	cin >> ch1;

	switch (std::toupper(ch1))  // <--- Allows for lower or upper case input. Changes to upper case if needed.
	{
		case 'B':
		{  // <--- Used to keep everything in one block.

                        // <--- Changed next line for better appearance in output.
			cout << "\n Burger 1 Rs. 200 = 1 \n Burger 2 Rs. 250 = 2 \n Burger 3 Rs. 300 = 3 \n Burger 4 Rs. 350 = 4\n Enter choice: ";
			cin >> ch1;  // <--- Changed. << to >>

			switch (ch1)
			{
			case '1':
                                 // <--- Changed next line for better appearance in output.
				cout << "\n For 1 Burger = A \n For 2 Burger = B\n For 4 Burger = C\n Enter Choice: ";
				std::cin >> ch1;  // <--- The "t" was undefined. "ch1" is all you need.
				break;
			}
			switch (std::toupper(ch1))
			{
			case 'A':
				std::cout << "\n Third switch\n" << std::endl;
				break;
			}
			break;  // <--- Break out of first case.
		}  // End of case B.

		case 'F':
			cout << " French Fries 1 Rs. 200 = 1 \n French Fries 2 Rs. 250 = 2 \n French Fries 3 Rs. 300 = 3 \n French Fries 4 Rs. 350 = 4 ";
			break;
		case 'P':
			cout << "Pizza 1 Rs. 200 = 1 \n Pizza 2 Rs. 250 = 2 \n Pizza 3 Rs. 300 = 3 \n Pizza 4 Rs. 350 = 4";
			break;
		case 'S':
			cout << "Sandwiches 1 Rs. 200 = 1 \n Sandwiches 2 Rs. 250 = 2 \n Sandwiches 3 Rs. 300 = 3 \n Sandwiches 4 Rs. 350 = 4";
			break;
		default:
			std::cout << "\n  Invalid choice. Try again." << std::endl;
			break;
	}

	// The next line may not be needed. If you have to press enter to see the prompt it is not needed.
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>.
	std::cout << "\n\n Press Enter to continue";
	std::cin.get();

	return 0;  // <--- Added, but not necessary. Good form though.
}

Only worked with case B. You can use the concept for all the other cases.

Hope that helps,

Andy
Topic archived. No new replies allowed.