I am having problems with finding a solution to update the quantity and list the menu items:
ex: if you select Plain eggs at 1.45 each 3 times and coffee at .50 each 2 times
it should output:
3 plain eggs $4.35
2 coffee $1.00
I have the total cost working fine. I have tried to add loops, but it seems to mess the code up even more.I am trying to add the quanties into the array menu_list[].quantity
Thanks
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
// declare struct
struct menuListType
{
string menu_item;
int menu_loc;
double menu_price;
int quantity;
};
//constant for tax rate
double RATE = .05;
//constant for array size
const int SIZE = 9;
// constant for column width
const int COL_WID = 20;
// prototype for funtion get data
void get_data(menuListType menu_list[SIZE]);
// prototype for funtion show menu
void show_menu(menuListType menu_list[SIZE], istream& in=cin, ostream& out=cout);
// prototype for funtion print check
void print_check(menuListType menu_list[SIZE], istream& in=cin, ostream& out=cout);
int main()
{
// Intro
cout << "This program will allow user to select several items on the " << endl;
cout << "menu and calculate total cost" << '\n' << '\n' << endl;
//array of type menuListType, size 8
menuListType menu_list[SIZE];
// call funtions
get_data(menu_list);
show_menu(menu_list);
print_check(menu_list);
return 0;
}
/*****************************************
Name: get_data
Purpose: gets menu list
Preconditions: set array to proper data
Postconditions: sets up array with proper data
*******************************************/
void get_data(menuListType menu_list[SIZE] )
{
// initialize data manually
menu_list[0].menu_loc = 1;
menu_list[0].menu_item = "Plain Eggs";
menu_list[0].menu_price = 1.45;
menu_list[0].quantity = 0;
menu_list[1].menu_loc = 2;
menu_list[1].menu_item = "Bacon and Eggs";
menu_list[1].menu_price = 2.45;
menu_list[1].quantity = 0;
menu_list[2].menu_loc = 3;
menu_list[2].menu_item = "Muffin";
menu_list[2].menu_price = 0.99;
menu_list[2].quantity = 0;
menu_list[3].menu_loc = 4;
menu_list[3].menu_item = "French Toast";
menu_list[3].menu_price = 1.99;
menu_list[3].quantity = 0;
menu_list[4].menu_loc = 5;
menu_list[4].menu_item = "Fruit Basket";
menu_list[4].menu_price = 2.49;
menu_list[4].quantity = 0;
menu_list[5].menu_loc = 6;
menu_list[5].menu_item = "Cereal";
menu_list[5].menu_price = 0.69;
menu_list[5].quantity = 0;
menu_list[6].menu_loc = 7;
menu_list[6].menu_item = "Coffee";
menu_list[6].menu_price = 0.50;
menu_list[6].quantity = 0;
menu_list[7].menu_loc = 8;
menu_list[7].menu_item = "Tea";
menu_list[7].menu_price = 0.75;
menu_list[7].quantity = 0;
menu_list[8].menu_loc = 9;
menu_list[8].menu_item = "EXIT";
menu_list[8].menu_price = 0;
menu_list[8].quantity = 0;
}
/*****************************************
Name: show_menu
Purpose: get info on menu
Preconditions: have array with proper data
Postconditions: shows menu list
*******************************************/
void show_menu(menuListType menu_list[SIZE], istream& in, ostream& out)
{
// output welcome
out << "Welcome to Kurt's Restuarant "<< '\n' << endl;
// ask user to select items on menu
out << "Enter the items you wish to order:" << '\n' << endl;
out << "Enter the quantity you wish to order:" << '\n' << endl;
// set precision for amount
out << setprecision(2) << showpoint << fixed;
// loop to out put menu list
for(int i = 0; i < SIZE; i++)
{
out << left << setw(3) << menu_list[i].menu_loc <<setw(COL_WID) << menu_list[i].menu_item << menu_list[i].menu_price << endl;
}
}
void print_check(menuListType menu_list[SIZE], istream& in, ostream& out)
{
// declare variable for order
int order = 0;
// declare variable for cost
double cost = 0;
//declare variable to count
int count = 0;
int n = 0;
// do loop to keep asking user for selection of menu
do
{
out << "What item would you like order" << endl;
// order item
in >> order;
// add the cost as selections are selected
cost += menu_list[order-1].menu_price;
out << endl;
// Add the next element to the total
out << menu_list[order-1].menu_item <<" "<< menu_list[order-1].menu_price << " " <<menu_list[order-1].quantity << endl;
//output menu selction and price
// close loop if 9 selected
}while (order != 9);
// output total bill
out <<menu_list[order-1].quantity << endl;
out << "Amount Due: " <<"$ " <<cost * RATE + cost << endl;
}