Having some trouble with this C++ program.
I need to rewrite it so that the customer can select multiple items of the same type like:
1 Bacon and Egg $2.45
2 Muffin $1.98
1 Coffee $0.50
A muffin normally costs $0.99, but he ordered two. Right now you can only order one of each. Help would be appreciated!
The Original Assignment
Write a program to help a local restaurant automate its breakfast billing system.
The program should do the following:Show the customer the differnt breakfast items offered by the restaurant.
Allow the customer to slect more than one item from the menu.
Calculate and print the bill.
Assume that the restaurant offers the following breakfast items/prices:
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 the struct menuItemType, as defined in programming ex 3. Your program must contain at least the following functions: getData(): loads the data into the array menuList showMenu(): Shows the different items offered by the restaurant and tells the user how to select the items, printCheck(): calculates and prints the check
*Note - Bill includes 5% tax
Here's 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
|
#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(vector <menuItemType> menuOrder);
int main()
{
// Declare functions and variables
const int menuItems = 8;
menuItemType menuList[menuItems];
vector< menuItemType > menuOrder;
int orderChoice = 0;
bool ordering = true;
int count = 0;
// Set the menu
getData(menuList);
// Order
showMenu(menuList, menuItems);
while(ordering)
{
cout << "Please enter the number for the item you would\n"
<< "like to order, or enter [0] to complete your order."
<< endl;
cin >> orderChoice;
if (orderChoice > 0 && orderChoice <= menuItems)
{
menuOrder.push_back(menuList[orderChoice-1]);
}
else
ordering = false;
}
printCheck(menuOrder);
return 0;
}
void getData(menuItemType menuList[])
{
// Declare menuItemTypes
menuItemType plainEgg;
menuItemType baconEgg;
menuItemType muffin;
menuItemType frenchToast;
menuItemType fruitBasket;
menuItemType cereal;
menuItemType coffee;
menuItemType tea;
// Initialize menuItemTypes variables
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)
{
// Function variables
int count;
cout << "Welcome to Bob Evans!" << endl;
cout << "What would you to order?" << endl;
for(count = 0; count < x; count++)
{
cout << setw(2) << left << "[" << count + 1 << "]"
<< menuList[count].menuItem << '$'
<< menuList[count].menuPrice << endl;
}
}
void printCheck(vector<menuItemType> menuOrder)
{
double checkTotal = 0;
double checkTax = 0;
const double TAX = .05;
cout << "Thanks for eating at Bob Evans!"
<< "Customer check: " << endl;
for(int i = 0; i < menuOrder.size(); i++)
{
cout << setprecision(2) << setw(10) << left << menuOrder[i].menuItem
<< '$' << menuOrder[i].menuPrice << endl;
checkTotal += menuOrder[i].menuPrice;
}
checkTax = checkTotal * TAX;
checkTotal += checkTax;
cout << setw(14) << left << "Tax" << checkTax << endl
<< setw(14) << left << "Total" << checkTotal << endl;
}
|