Question

Need help with a C++ problem I have

For my assignment I have to write a program that creates a restaurant billing system. I think that I got it correct but it says that it is incorrect, so I was wondering if someone would be able to look over my code. It says that I need tax of $0.20, and the amount due to be $4.10, which is what I have in my output.

https://imgur.com/a/jgglmvW

My issue is that I have the correct outcome when I run my program but it doesn't seem to be counted with the program that I am working with. Could someone look at my code to see if I have any issues? I think that I got it correct but it says that it is incorrect. It says that I need tax of $0.20, and the amount due to be $4.10, which is what I have in my output. I might be able to get it to work if I can get my output which is currently Tax $ 0.20, and $ 4.10 into $0.20 and $4.10, but I am not sure what I would need to do in order to remove the spaces that I am getting in my code.

Here is my assignment.

Write a program to help a local restaurant automate its breakfast billing system. The program should do the following:

Show the customer the different breakfast items offered by the restaurant. Allow the customer to select more than one item from the menu. Calculate and print the bill. Assume that the restaurant offers the following breakfast items (the price of each item is shown to the right of the item):

food Price Plain Egg $1.45 Bacon and Egg $2.45 Muffin $0.99 French Toast $1.99 Fruit Basket $2.49 Cereal $0.69 Coffee $0.50 Tea $0.75 Use an array menuList of type menuItemType, as defined in Programming Exercise 3. Your program must contain at least the following functions:

Function getData: This function loads the data into the array menuList. Function showMenu: This function shows the different items offered by the restaurant and tells the user how to select the items. Function printCheck: This function calculates and prints the check. (Note that the billing amount should include a 5% tax.) 


Here is my code:

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;

struct MenuItem{
    string description;
    double price;
    int quantity;};const int MAX_ITEMS = 20;const double TAX_RATE = 5;void getData(MenuItem menuList[], int &size);void showMenu(MenuItem menuList[], int size);void printCheck(MenuItem menuList[], int size);int main(){
    MenuItem menuList[MAX_ITEMS];
    int size = 0;
    
    getData(menuList, size);
    showMenu(menuList, size);
    printCheck(menuList, size);
    
    return 0;}void getData(MenuItem menuList[], int &size){
    menuList[0] = {"Plain Egg", 1.45, 0 };
    menuList[1] = {"Bacon and Egg", 2.45, 0};
    menuList[2] = {"Muffin", 0.99, 0};
    menuList[3] = {"French Toast", 1.99, 0};
    menuList[4] = {"Fruit Basket", 2.49, 0};
    menuList[5] = {"Cereal", 0.69, 0};
    menuList[6] = {"Coffee", 0.50, 0};
    menuList[7] = {"Tea",0.75,0};
    
    size = 8;}void showMenu(MenuItem menuList[], int size){
    cout    << "Welcome to Johnny's Restaurant\n"
    << "----------MENU ITEMS----------\n";
    
    for (int i = 0; i < size; i++)
    {
        cout        << (i + 1) << ". "
        << left << setw(20)
        << menuList[i].description        << "$"
        << setw(6) << setprecision(2) << fixed        << menuList[i].price        << '\n';
    }
    cout    << "------------------------------\n\n";
    
    int num{0};
    int qty{0};
    
    while (
           cout           << "Enter the item number (1-8) (-1 for exit): "
           && cin >> num           && num != -1
           )
    {
        if (num >= 1 && num <= 8)
        {
            cout << "Enter no. required: ";
            cin >> qty;
            
            menuList[num - 1].quantity += qty;
        }
        else
        {
            cout << "Invalid item number!\n";
        }
    }}void printCheck(MenuItem menuList[], int size){
    double totalPrice = 0;
    double taxAmount = 0;
    
    cout    << "Your Bill...\n\n"
    << "Welcome to Johnny's Restaurant\n";
    
    for (int i = 0; i < size; i++)
    {
        if (menuList[i].quantity > 0)
        {
            cout            << setw(20) << right            << menuList[i].description            << right << setw(6) << fixed            << menuList[i].quantity            << "  $"
            << right << setw(6) << setprecision(2) << fixed            << menuList[i].price            << "  $"
            << right << setw(6) << setprecision(2) << fixed            << menuList[i].price * menuList[i].quantity            << '\n';
            
            totalPrice += (menuList[i].price * menuList[i].quantity) ;
        }
    }
    
    taxAmount = round(totalPrice * TAX_RATE) / 100;
    
    cout    << '\n'
    << setw(38) << right    << "Sub total: $"
    << right << setw(6) << setprecision(2) << fixed    << totalPrice << '\n'
    
    << setw(38) << right    << "Tax: $"
    << right << setw(6) << setprecision(2) << fixed    << taxAmount << "\n\n"
    
    << setw(38) << right    << "Amount Due: $"
    << right << setw(6) << setprecision(2) << fixed    << totalPrice + taxAmount    
    << "\n\n";}
0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Need help with a C++ problem I have
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • #include <iostream> #include <iomanip> #include <vector> #include <string> using namespace std; struct menuItemType { string menuItem;...

    #include <iostream> #include <iomanip> #include <vector> #include <string> using namespace std; struct menuItemType { string menuItem; double menuPrice; }; void getData(menuItemType menuList[]); void showMenu(menuItemType menuList[], int x); void printCheck(menuItemType menuList[], int menuOrder[], int x); int main() { const int menuItems = 8; menuItemType menuList[menuItems]; int menuOrder[menuItems] = {0}; int orderChoice = 0; bool ordering = true; int count = 0; getData(menuList); showMenu(menuList, menuItems); while(ordering) { cout << "Enter the number for the item you would\n" << "like to order, or...

  • c++ Write a C++ program using the struct keyword to help a local restaurant automate its...

    c++ Write a C++ program using the struct keyword to help a local restaurant automate its breakfast billing system The program should do the following: a. Show the customer the different breakfast items offered by the restaurant. b. Allow the customer to select more than one item from the menu. c. Calculate and print the bill. Assume that the restaurant offers the following breakfast items (the price of each item is shown to the right of the item) Menu Plain...

  • Can anyone help me with my C++ assignment on structs, arrays and bubblesort? I can't seem...

    Can anyone help me with my C++ assignment on structs, arrays and bubblesort? I can't seem to get my code to work. The output should have the AVEPPG from highest to lowest (sorted by bubbesort). The output of my code is messed up. Please help me, thanks. Here's the input.txt: Mary 15 10.5 Joseph 32 6.2 Jack 72 8.1 Vince 83 4.2 Elizabeth 41 7.5 The output should be: NAME             UNIFORM#    AVEPPG Mary                   15     10.50 Jack                   72      8.10 Elizabeth              41      7.50 Joseph                 32      6.20 Vince                  83      4.20 ​ My Code: #include <iostream>...

  • Expand the payroll program to combine two sorting techniques (Selection and Exchange sorts) for better efficiency...

    Expand the payroll program to combine two sorting techniques (Selection and Exchange sorts) for better efficiency in sorting the employee’s net pay. //I need to use an EXSEL sort in order to combine the selection and Exchange sorts for my program. I currently have a selection sort in there. Please help me with replacing this with the EXSEL sort. //My input files: //My current code with the sel sort. Please help me replace this with an EXSEL sort. #include <fstream>...

  • I need a detailed pseudocode for this code in C ++. Thank you #include <iostream> #include...

    I need a detailed pseudocode for this code in C ++. Thank you #include <iostream> #include <string> #include <iomanip> using namespace std; struct Drink {    string name;    double cost;    int noOfDrinks; }; void displayMenu(Drink drinks[], int n); int main() {    const int size = 5;       Drink drinks[size] = { {"Cola", 0.65, 2},    {"Root Beer", 0.70, 1},    {"Grape Soda", 0.75, 5},    {"Lemon-Lime", 0.85, 20},    {"Water", 0.90, 20} };    cout <<...

  • IN C# Write a program to help a local restaurant automate its lunch billing system. The...

    IN C# Write a program to help a local restaurant automate its lunch billing system. The program should do the following: Show the customer the different lunch items offered by the restaurant. Allow the customer to select more than one item from the menu. Calculate and print the bill. Assume that the restaurant offers the following lunch items (the price of each item is shown to the right of the item): Ham and Cheese Sandwich $5.00 Tuna Sandwich $6.00 Soup...

  • The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib>...

    The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib> #include <iomanip> #define MAX 1000 using namespace std; //Function to Add a new inventory item to the data into the array in memory void addItem(string desc[],string idNum[], float prices[], int qty[],int &num) { cout<<"Enter the names:"; cin>>desc[num]; cout<<"Enter the item number:"; cin>>idNum[num]; cout<<"Enter the price of item:"; cin>>prices[num]; cout<<"Enter the...

  • In C++ Programming Write a program in to help a local restaurant automate its breakfast

    Write a program to help a local restaurant automate its breakfast billing system. The program should do the following:Show the customer the different breakfast items offered by the restaurant.Allow the customer to select more than one item from the menu.Calculate and print the bill.Assume that the restaurant offers the following breakfast items (the price of each item is shown to the right of the item):Use an array menuList of type menuItemType, as defined in Programming Exercise 3. Your program must contain at least the...

  • I want to change this code and need help. I want the code to not use...

    I want to change this code and need help. I want the code to not use parallel arrays, but instead use one array of struct containing the data elements, String for first name, String for last name,Array of integers for five (5) test scores, Character for grade. If you have any idea help would be great. #include #include #include #include using namespace std; const int NUMBER_OF_ROWS = 10; //number of students const int NUMBER_OF_COLUMNS = 5; //number of scores void...

  • Hello, I have written a code that I now need to make changes so that arrays...

    Hello, I have written a code that I now need to make changes so that arrays are transferred to the functions as pointer variable. Below is my code I already have. #include<iostream> #include<string> #include<iomanip> using namespace std; //functions prototypes void getData(string id[], int correct[], int NUM_STUDENT); void calculate(int correct[], int incorrect[], int score[], int NUM_STUDENT); double average(int score[], int NUM_STUDENT); void Display(string id[], int correct[], int incorrect[], int score[], double average, int NUM_STUDENT); int findHigh(string id[], int score[], int NUM_STUDENT);...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT