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
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.
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.
#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.
usingnamespace 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.