Question

In: Computer Science

I'm having a bit of an issue with one of my C++ labs. It's not for...

I'm having a bit of an issue with one of my C++ labs. It's not for score but I need to understand it so I can move on.

A restaurant servers burgers for $8 and salads for $7.

When the customer selects a burger they must choose if they would like cheese. If they do, cheddar costs an additional 25 cents while pepper jack is 50 cents.

When the customer selects a salad they must choose if they would like no dressing, ranch for 10 cents more, and honey mustard for 15 cents more.

Customers can buy a drink for $1.50

Use the question prompts already declared as strings to ask the user for responses and then calculate the total cost the customer owes.

The code I wrote is as follows:

#include <iostream>
using namespace std;

int main() {

   int burgerOrSalad, cheese, kindOfCheese, dressing, drink;
  
   string q1 = "Would you like a 1) burger or 2) a salad?";
   string q2 = "Would you like cheese? 0) No or 1) Yes";
   string q3 = "What kind of cheese 1) Cheddar or 2) Pepper jack?";
   string q4 = "What kind of dressing would you like 0) None, 1) Ranch, 2) Honey Mustard?";
   string q5 = "Would you like a drink? 0) No, 1) Yes";

   cout << q1 << endl;
   cin >> burgerOrSalad;

   double cost = 0;

   cout << q2 << endl;
   cin >> cheese;

   cout << q3 << endl;
   cin >> kindOfCheese;

   cout << q4 << endl;
   cin >> dressing;

   cout << q5 << endl;
   cin >> drink;
    
   if ( burgerOrSalad == 1 ) {
       cost = 8.00;
   }
      if ( cheese == 1 ) {
      }
         else if ( kindOfCheese == 1 ) {
            cost = 8.25;
         }
         else if ( kindOfCheese == 2 ) {
            cost = 8.50;
         }

   if ( burgerOrSalad == 2 ) {
       cost = 7.00;
   }
      else if ( dressing == 1 ) {
         cost = 7.10;
      }
      else if ( dressing == 2 ) {
         cost = 7.15;
      }

   if ( drink == 1 ) {
       cost = 1.50;
   }
   cout << "Total cost of selected meal is " << cost << endl;
   return 0;
}

How can I add the cost if the input is 1 1 1 1?

I'm so lost.

Solutions

Expert Solution

#include <iostream>
using namespace std;

int main() {

   int burgerOrSalad, cheese, kindOfCheese, dressing, drink;
  
   string q1 = "Would you like a 1) burger or 2) a salad?";
   string q2 = "Would you like cheese? 0) No or 1) Yes";
   string q3 = "What kind of cheese 1) Cheddar or 2) Pepper jack?";
   string q4 = "What kind of dressing would you like 0) None, 1) Ranch, 2) Honey Mustard?";
   string q5 = "Would you like a drink? 0) No, 1) Yes";

   cout << q1 << endl;
   cin >> burgerOrSalad;

   double cost = 0;
   
   // if customer wants burger then only ask him for cheese
   if(burgerOrSalad == 1) {

        cout << q2 << endl;
        cin >> cheese;

        // ask q3 only if person wants cheese
        if(cheese == 1) {
                cout << q3 << endl;
                cin >> kindOfCheese;
        }
   } else {
        cout << q4 << endl;
        cin >> dressing;

   }


   cout << q5 << endl;
   cin >> drink;
    
   if ( burgerOrSalad == 1 ) {
      cost = 8.00;
      if ( cheese == 1 ) {
         if ( kindOfCheese == 1 ) {
            cost = 8.25;
         }
         else if ( kindOfCheese == 2 ) {
            cost = 8.50;
         }
      }
   } 

   else if ( burgerOrSalad == 2 ) {
       cost = 7.00;
       
       // only in case of salad, check the dressing price:
      if ( dressing == 1 ) {
         cost = 7.10;
      }
      else if ( dressing == 2 ) {
         cost = 7.15;
      }

   }
   
   // if customer wants drink also, apart from burger or salad,
   // then add the drink's cost to total cost whatsoever till now.
   if ( drink == 1 ) {
       cost += 1.50;
   }
   
   cout << "Total cost of selected meal is " << cost << endl;
   return 0;
}
**************************************************
I have added comments which will help you.

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.


Related Solutions

Thanks in advance. In Java. I'm having an issue with one of my methods. Ex: The...
Thanks in advance. In Java. I'm having an issue with one of my methods. Ex: The array being pass in is a character array with element: w, ' ', K, Q, k, q, ' ', -, ' ', 0, ' ', 1 public class Find { public void enPassant(char[] array) {   for(int i = 0; i < array.length; ++i) { if(array[i] == 'e') { count = i; } else { count += 0; } }    if(count > 0) {...
Ok, so I'm struggling a bit with my labs being online due to covid. I was...
Ok, so I'm struggling a bit with my labs being online due to covid. I was provided this information and an empty table. "Sorghum is a genus of grass containing 25 species. Several species are grown in cultivation as livestock feed and one, Sorghum bicolor, is grown widely as a grain for human consumption and also for production of molasses and ethanol. It is one of the top five grain crops grown and consumed worldwide (along with wheat, corn, rice,...
I'm having trouble trying to create the italian, polish, and netherlands flag in C Here's my...
I'm having trouble trying to create the italian, polish, and netherlands flag in C Here's my code so far: #include<stdio.h> int main(){    int country_choice;    fprintf(stderr, "Enter the country_code of the chosen flag.(1 for Poland, 2 for Netherlands, 3 for Italy)");    fscanf(stdin, "%d", &country_choice);    switch (country_choice) { case 1: printf("Poland Flag\n"); printf("%c%c%c", 255,255,255); printf("%c%c%c", 220,20,60);    break;       case 2: printf("Italian Flag\n"); printf("%c%c%c", 0,146,70); printf("%c%c%c", 225,255,255); printf("%c%c%c", 206,43,55); break;    case 3: printf("Netherlands Flag\n"); printf("%c%c%c", 174,28,40);...
I'm having trouble with my do while loop. I'm trying to get it where if the...
I'm having trouble with my do while loop. I'm trying to get it where if the user enter's 3 after whatever amount of caffeinated beverages they've entered before then the loop will close and the rest of my code would proceed to execute and calculate the average price of all the caffeinated beverages entered. Can someone please help me with this? Here's my Code: import java.util.Scanner; public class Main { public static void main(String[] args) { CaffeinatedBeverage[] inventory = new...
I'm having a very hard time getting this c++ code to work. I have attached my...
I'm having a very hard time getting this c++ code to work. I have attached my code and the instructions. CODE: #include using namespace std; void printWelcome(string movieName, string rating, int startHour, int startMinute, char ampm); //menu function //constants const double TICKET_PRICE = 9.95; const double TAX_RATE = 0.095; const bool AVAILABLE = true; const bool UNAVAILABLE = false; int subTotal,taxAdded, totalCost; // bool checkAvailability( int tickets, int& seatingLeft){ //checks ticket availability while(tickets > 0 || tickets <= 200) //valid...
We are learning about The Iliad in mythology and I'm having a bit of troble understanding...
We are learning about The Iliad in mythology and I'm having a bit of troble understanding the context. Can someone summarize the story for me to better understand and assist me with these questions! Can we view the behavior of Agamemnon or Achilles as appropriate for heroes? How does the characterization of Hector help define heroic behavior for early Greeks?
We are learning about The Iliad in mythology and I'm having a bit of troble understanding...
We are learning about The Iliad in mythology and I'm having a bit of troble understanding the context. Can someone summarize the story for me to better understand and assist me with these questions! Can we view the behavior of Agamemnon or Achilles as appropriate for heroes? How does the characterization of Hector help define heroic behavior for early Greeks?
We are learning about Ramayana in Mythology and I'm having a bit of trouble understanding the...
We are learning about Ramayana in Mythology and I'm having a bit of trouble understanding the story. Why would Rama be set apart as a true hero? The story of Rama and Sita is a favorite story that parents tell their children. What purpose does the Ramayana serve as an instructional story for Indian culture? What effect do the test and temptations have on the heroic character?
Having an issue with question C. My answer continues to be incorrect. Thank you. McGriff Dog...
Having an issue with question C. My answer continues to be incorrect. Thank you. McGriff Dog Food Company normally takes 27 days to pay for average daily credit purchases of $9,460. Its average daily sales are $10,700, and it collects accounts in 27 days.      a. What is its net credit position?    b-1. If the firm extends its average payment period from 27 days to 38 days (and all else remains the same), what is the firm's new net...
XML and XSL I'm trying to style my XML code but it's not implementing the XSL...
XML and XSL I'm trying to style my XML code but it's not implementing the XSL file when I run it even though the file is referenced. Any help? XML code: <?xml version="1.0"?> <?xml-stylesheet href="textbooks.xsl" type="text/xsl" ?> <textbooks> <textbook> <title> Introduction to Design and Analysis of Algorithms</title> <authors> <author> <firstName>Anany</firstName> <lastName>Levitin</lastName> </author> </authors> <publisher> <name>Ed, Pearson</name> <website>https://www.pearson.com</website> </publisher> <Year-of-Publication>2011</Year-of-Publication> <ISBN>978-0132316811</ISBN> <book-specific-website></book-specific-website> <edition>3rd edition</edition> <cover-type>Paperback</cover-type> </textbook> <textbook> <title>Software Engineering: A Practitioner’s Approach</title> <authors> <author> <firstName>Roger</firstName> <lastName>Pressman</lastName> </author> </authors> <publisher> <name>Ed, McGraw-Hill</name>...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT