I am having an issue with this 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
Format your output with two decimal places. The name of each item in the output must be left justified. You may assume that the user selects only one item of a particular type.
The main part I am havig trouble with is in this section of the coding here
( showMenu(menuList, menuItems);
while(ordering || choice == 'Y' || choice == 'y')
{
cout << "Do you want to make selection Y/y (Yes), N/n (No): " << endl;
cin >> choice;
cout << "Enter item number" << endl;
cin >> orderChoice;
do
{
if (orderChoice > 0 && orderChoice <= menuItems)
{
menuOrder[orderChoice - 1] += 1;
cout << "Select another item Y/y (Yes), N/n (No): " << endl;
cin >> choice1;
cout << "Enter item number" << endl;
cin >> orderChoice;
}
else
ordering = false;
}
while (orderChoice > 0 && orderChoice <= menuItems && choice1 == 'Y' && choice1 == 'y');
printCheck(menuList, menuOrder, menuItems);
cin.ignore(2);
return 0;
}
)
If I take out the do while the program kinda works right if I say Y/y it asks for the number if I enter a number it asks the message again. however if I say N/n or hit 0 it still prompts the next message and I have to hit 0 two times for it to go to the rest of the code. with the statement in the coding like now I get an error message saying a function is not allowed before all of my Void sections. I have been stuck for a few days and my assignment is due on Monday. Can someone please show me what I have done wrong and how to fix it.
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
|
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;
//struct for menuItemType
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;
char choice;
char choice1;
getData(menuList);
showMenu(menuList, menuItems);
while(ordering || choice == 'Y' || choice == 'y')
{
cout << "Do you want to make selection Y/y (Yes), N/n (No): " << endl;
cin >> choice;
cout << "Enter item number" << endl;
cin >> orderChoice;
do
{
if (orderChoice > 0 && orderChoice <= menuItems)
{
menuOrder[orderChoice - 1] += 1;
cout << "Select another item Y/y (Yes), N/n (No): " << endl;
cin >> choice1;
cout << "Enter item number" << endl;
cin >> orderChoice;
}
else
ordering = false;
}
while (orderChoice > 0 && orderChoice <= menuItems && choice1 == 'Y' && choice1 == 'y');
printCheck(menuList, menuOrder, menuItems);
cin.ignore(2);
return 0;
}
void getData(menuItemType menuList[])
{
menuItemType plainEgg;
menuItemType baconEgg;
menuItemType muffin;
menuItemType frenchToast;
menuItemType fruitBasket;
menuItemType cereal;
menuItemType coffee;
menuItemType tea;
plainEgg.menuItem = "Plain Egg";
plainEgg.menuPrice = 1.45;
baconEgg.menuItem = "Bacon and Egg";
baconEgg.menuPrice = 2.45;
muffin.menuItem = "Muffin";
muffin.menuPrice = 0.99;
frenchToast.menuItem = "French Toast";
frenchToast.menuPrice = 1.99;
fruitBasket.menuItem = "Fruit Basket";
fruitBasket.menuPrice = 2.49;
cereal.menuItem = "Cereal";
cereal.menuPrice = 0.69;
coffee.menuItem = "Coffee";
coffee.menuPrice = 0.50;
tea.menuItem = "Tea";
tea.menuPrice = 0.75;
menuList[0] = plainEgg;
menuList[1] = baconEgg;
menuList[2] = muffin;
menuList[3] = frenchToast;
menuList[4] = fruitBasket;
menuList[5] = cereal;
menuList[6] = coffee;
menuList[7] = tea;
}
void showMenu(menuItemType menuList[], int x)
{
int count;
cout << "Welcome to Johnny's Resturant" << endl;
cout << "You can make up to 8 single order selections" << endl;
for(count = 0; count < x; count++)
{
cout << setw(2) << left << "[" << count + 1 << "]"
<< menuList[count].menuItem << '$'
<< menuList[count].menuPrice << endl;
}
}
void printCheck(menuItemType menuList[], int menuOrder[], int menuItems)
{
double checkTotal = 0;
double checkTax = 0;
const double TAX = .05;
cout << "Thanks for eating at Johnny's"
<< "Customer check: " << endl;
for(int i = 0; i < menuItems; i++)
{
if(menuOrder[i] > 0) {
cout << setprecision(3) << setw(10) << left << menuList[i].menuItem
<< '$' << (menuList[i].menuPrice * menuOrder[i]) << endl;
checkTotal += (menuList[i].menuPrice * menuOrder[i]);
}
}
checkTax = checkTotal * TAX;
checkTotal += checkTax;
cout << setw(14) << left << "Tax" << checkTax << endl
<< setw(14) << left << "Total" << checkTotal << endl;
}
|