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.
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.)
A sample output is:
Welcome to Johnny's Resturant
----Today's Menu----
1: Plain Egg $1.45
2: Bacon and Egg $2.45
3: Muffin $0.99
4: French Toast $1.99
5: Fruit Basket $2.49
6: Cereal $0.69
7: Coffee $0.50
8: Tea $0.75
You can make up to 8 single order selections
Do you want to make selection Y/y (Yes), N/n (No): Y
Enter item number: 1
Select another item Y/y (Yes), N/n (No): Y
Enter item number: 2
Select another item Y/y (Yes), N/n (No): N
Welcome to Johnny's Resturant
Plain Egg $1.45
Bacon and Egg $2.45
Tax $0.20
Amount Due $4.10
Assignment images link
https://imgur.com/a/6nIlNyt
Here is my 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
// Header files section
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// MenuItem structure
struct MenuItem
{
string description;
double price;
int quantity;
};
// constants declaration
const int MAX_ITEMS = 20;
const double TAX_RATE = 0.05;
// function prototype
void getData(MenuItem menuList[], int &size);
void showMenu(MenuItem menuList[], int size);
void printCheck(MenuItem menuList[], int size);
// start main function
int main()
{
// create an array of items
MenuItem menuList[MAX_ITEMS];
int size = 0;
// call the getData function
getData(menuList, size);
// call the showMenu function
showMenu(menuList, size);
// call the printCheck function
printCheck(menuList, size);
return 0;
} // end of main function
// getData function implementation
// This function loads the data into the array menuList.
void getData(MenuItem menuList[], int &size)
{
menuList[0].description = "Plain Egg";
menuList[0].price = 1.45;
menuList[0].quantity = 0;
menuList[1].description = "Bacon and Egg";
menuList[1].price = 2.45;
menuList[1].quantity = 0;
menuList[2].description = "Muffin";
menuList[2].price = 0.99;
menuList[2].quantity = 0;
menuList[3].description = "French Toast";
menuList[3].price = 1.99;
menuList[3].quantity = 0;
menuList[4].description = "Fruit Basket";
menuList[4].price = 2.49;
menuList[4].quantity = 0;
menuList[5].description = "Cereal";
menuList[5].price = 0.69;
menuList[5].quantity = 0;
menuList[6].description = "Coffee";
menuList[6].price = 0.50;
menuList[6].quantity = 0;
menuList[7].description = "Tea";
menuList[7].price = 0.75;
menuList[7].quantity = 0;
size = 8;
} // end of getData function
// showMenu function implementation
// This function shows the different items offered by the restaurant and
// tells the user how to select the items.
void showMenu(MenuItem menuList[], int size)
{
cout << "Welcome to Johnny's Restaurant" << endl;
cout << "----------MENU ITEMS----------" << endl;
for (int i = 0; i < size; i++)
{
cout << (i + 1) << ". " << left << setw(21) << menuList[i].description << "$" << setw(6) << setprecision(2) << fixed << menuList[i].price << endl;
}
cout << "------------------------------" << endl;
int num;
int qty;
cout << "\nEnter the item number (1-8) (-1 for exit): ";
cin >> num;
while (num != -1)
{
if (num >= 1 && num <= 8)
{
menuList[num - 1].quantity = 1;
}
else
{
cout << "Invalid item number!" << endl;
}
cout << "Enter the item number (1-8) (-1 for exit): ";
cin >> num;
}
} // end of showMenu function
// printCheck function implementation
// This function calculates and prints the check.
// (Note that the billing amount should include a 5 % tax.)
void printCheck(MenuItem menuList[], int size)
{
double totalPrice = 0;
double taxAmount = 0;
cout << "\nYour Bill..." << endl;
cout << endl << "Welcome to Johnny's Restaurant" << endl;
for (int i = 0; i < size; i++)
{
if (menuList[i].quantity > 0)
{
cout << left << setw(20) << menuList[i].description << "$" << setw(10) << setprecision(2) << fixed << menuList[i].price << endl;
totalPrice += menuList[i].price;
}
}
taxAmount = totalPrice * TAX_RATE;
cout << setw(20) << "Tax:"<< "$" << setw(10) << setprecision(2) << fixed << taxAmount << endl;
cout << setw(20) << "Amount Due:" << "$" << setw(10) << setprecision(2) << fixed << (totalPrice + taxAmount) << endl << endl;
} // end of printCheck function
|