Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The top half is what I need to do and the second is what I did. I am doing somet

ID: 3888225 • Letter: T

Question






The top half is what I need to do and the second is what I did. I am doing something wrong but I don't understand what I am doing wrong.

1. Problem Statement: The goal of this programming assignment is to give students experience creating an interactive program that uses nested conditional statements to implement a series of menus. In particular, your task is to write a program that simulates a web service where users can order food items at three popular restaurants. To meet these goals, your program should do the following: Print a message asking the user which restaurant they wish to order from (e.g. McDonald's, Wendy's or Chick-fil-A). You should also include instructions on what to enter to select a restaurant. For example, one option is to use integers 1,2,3. Another option is to use single characters M,W,C. It is up to you to choose what the user should type. Read the user's input from above, and use this information to decide what list of food menu items to print. To keep things short and simple, your three menus should only include five items each. For each menu item, you should print the name of the item and the price of the item (e.g. Big Mac Meal $5.99). You should also print instructions on what the user must type to select an item. For example integers 1,2,3,4,5 or single characters A,B,C,D,E. Again, this is up to you . Read the user's input of the menu item they wish to buy, and ask them how many orders of that item they want to buy. Read the integer item quantity from the user, and calculate and print the total cost for this purchase using the formula "total cost- item price*tem quantity sales tax". To keep things simple, lets pretend the sales tax rate is 5% of the purchase price Your program should do some basic error checking. If the user does not choose a restaurant correctly, your program should print the message "Sorry, that restaurant is not available" and exit. If the user types in an invalid food item, your program should print the message "Sorry, that is an food item is not available" and exit. Finally, if the user enters a negative quantity, the program should print the message "Sorry, item quantity must be positive" and exit. You do NOT need to loop asking the user to enter their choice again. . is project is about conditional statements (and not loops) you are NOT red to handle multiple orders at one time. The user will just have to run your program a second time to order something else. 2. Design: This nrgiect is all ahout nrinting messages reading user innuts and nerforming

Explanation / Answer

Some mistakes in the code :

1. When you check if the item number is correct , the statements should be enclosed in { } . Because there are no { }, the compiler assumes only the 1st line following if( ) is to be executed for true condition and the following return 0; will always be executed. So when you enter an invalid choice, you get the error message and the program terminates since return 0 will be executed. When you enter a valid choice, there is no error message but the return 0 terminates the program.

Suggestion: Always its better to use { } even when there is single statement. This way we are clear which statements to be executed for if-part and which ones for else-part

2. When order < 0, there are no statements to execute. The compiler will complain because else is appearing iwthout an if block of statements.

3. Also when you calculate the cost, you are not considering the order quantity. So the calculated value would be only for 1 item

==============

Given below is the code that funcitons as desired. I have a suggestion for you, when you paste your code in question, always copy paste as text rather than image. This way it is easier to modify your code rather than typing it out again. Especially when the code runs into pages, it will be easier to copy paste text. Also the existing comments and formatting will not be lost.

Hope the answer helped. If it did, please do rate the answer. Thank you very much.

#include <iostream>
using namespace std;
int main()
{
float cost;
const float rate = 1.05;
int orders = 0;
int choice = 0;
  
  
cout << "1. McDonalds" << endl;
cout << "2. Wendy's" << endl;
cout << "3. Chick-fil-A" << endl;
cout<< "Which restaurant would you like to order from [1-3]? ";
cin >> choice;
  
if(choice < 1 || choice > 3)
{
cout << "Invalid restaurant choice" << endl;
}
else
{
if(choice == 1)
{
//print menu for McDonald
cout << "Welcome to McDonald's" << endl;
cout << "1. Big Mac $5.99" << endl;
cout << "2. Egg McMuffin $2.34" << endl;
cout << "3. Signature Sriracha $5.46" << endl;
cout << "4. Pico Guacamole $6.29" << endl;
cout << "5. Signature Sriracha Buttermilk Cripsy Chicken Sandwich $ 6.45" << endl;
cout << "What would you like today [1-5]? " ;
cin >> choice;
  
  
if(choice < 1 || choice > 5)
{
cout << "Invalid item chosen" << endl;
}
else
{
cout << "How many orders? ";
cin >> orders;
  
if(orders <= 0)
{
cout << "Invalid order quantity." << endl;
}
else
{
if(choice == 1) cost = orders * 5.99 * rate;
else if(choice == 2) cost = orders * 2.34 * rate;
else if(choice == 3) cost = orders * 5.46 * rate;
else if(choice == 4) cost = orders * 6.29 * rate;
else if(choice == 5) cost = orders * 6.45 * rate;
  
cout << "Your order costs $" << cost << endl;
}
  
}
}
else if(choice == 2)
{
//print menu for Wendy
cout << "Welcome to Wendy's" << endl;
cout << "1. Dave's Single $6.99" << endl;
cout << "2. Son of Baconatar $4.36$" << endl;
cout << "3. Jr Hamburger $4.44$" << endl;
cout << "4. Spicey Chicken Sandwich $7.50" << endl;
cout << "5. Spicey Asian Club $7.50" << endl;
cout << "What would you like today [1-5]? " ;
cin >> choice;
  
if(choice < 1 || choice > 5)
{
cout << "Invalid item chosen" << endl;
}
else
{
cout << "How many orders? ";
cin >> orders;
if(orders <= 0)
{
cout << "Invalid order quantity." << endl;
}
else
{

if(choice == 1) cost = orders * 6.99 * rate;
else if(choice == 2) cost = orders * 4.36 * rate;
else if(choice == 3) cost = orders * 4.44 * rate;
else if(choice == 4) cost = orders * 7.5 * rate;
else if(choice == 5) cost = orders * 7.5 * rate;
  
cout << "Your order costs $" << cost << endl;
}
  
}

}
else
{
  
//print menu for Chick fil A
  
cout << "Welcome to Chick-Fil-A" << endl;
cout << "1. Chicken Sandwich $3.99" << endl;
cout << "2. Delux Chicken Sandwich $4.99" << endl;
cout << "3. Spicy Sandwich $3.99" << endl;
cout << "4. Spicy Deluxe Sandwich $4.99" << endl;
cout << "5. Nuggets $5.99" << endl;
cout << "What would you like today[1-5]? " ;
cin >> choice;
  
if(choice < 1 || choice > 5)
{
cout << "Invalid item chosen" << endl;
}
else
{
cout << "How many orders? ";
cin >> orders;
  
if(orders <= 0)
{
cout << "Invalid order quantity." << endl;
}
else
{

if(choice == 1) cost = orders * 3.99 * rate;
else if(choice == 2) cost = orders * 4.99 * rate;
else if(choice == 3) cost = orders * 3.99 * rate;
else if(choice == 4) cost = orders * 4.99 * rate;
else if(choice == 5) cost = orders * 5.99 * rate;
  
cout << "Your order costs $" << cost << endl;
}
  
}

}
}
}

output

$ g++ restaurants.cpp
$ ./a.out
1. McDonalds
2. Wendy's
3. Chick-fil-A
Which restaurant would you like to order from [1-3]?
1
Welcome to McDonald's
1. Big Mac $5.99
2. Egg McMuffin $2.34
3. Signature Sriracha $5.46
4. Pico Guacamole $6.29
5. Signature Sriracha Buttermilk Cripsy Chicken Sandwich $ 6.45
What would you like today [1-5]? 3
How many orders? 4
Your order costs $22.932

$ ./a.out
1. McDonalds
2. Wendy's
3. Chick-fil-A
Which restaurant would you like to order from [1-3]? 5
Invalid restaurant choice

$ ./a.out
1. McDonalds
2. Wendy's
3. Chick-fil-A
Which restaurant would you like to order from [1-3]? 0
Invalid restaurant choice

$ ./a.out
1. McDonalds
2. Wendy's
3. Chick-fil-A
Which restaurant would you like to order from [1-3]? 2
Welcome to Wendy's
1. Dave's Single $6.99
2. Son of Baconatar $4.36$
3. Jr Hamburger $4.44$
4. Spicey Chicken Sandwich $7.50
5. Spicey Asian Club $7.50
What would you like today [1-5]? 7
Invalid item chosen

$ ./a.out

1. McDonalds
2. Wendy's
3. Chick-fil-A
Which restaurant would you like to order from [1-3]?
3
Welcome to Chick-Fil-A
1. Chicken Sandwich $3.99
2. Delux Chicken Sandwich $4.99
3. Spicy Sandwich $3.99
4. Spicy Deluxe Sandwich $4.99
5. Nuggets $5.99
What would you like today[1-5]? 3
How many orders? -1
Invalid order quantity.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote