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;
		

}

So here I was sitting in my high school online C++ Class. I was bored and was trying to work out your problem... and all f a sudden I accidentally type '11' My computer starts freaking out and beeping(not usually a good sign...) and my instructor asks what's going on... Well, I told her that nothing happened... and continued on trying to work out your problem... I compiled your program before I wanted to(after adding what you already had back into my code.. so I could start over...) and so I naturally type '0' the first time around before ordering anything... expecting it to naturally close like it always had been....

Well it decided to freak out on me again, spitting out machine language onto the screen again, and beeping like crazy, causing my instructor to walk over and see what was happening...

I have no clue what's wrong with your program now... but I'd rather not get in trouble for "destroying a computer" as she says... so... I'll leave it up to one of the more knowledgeable people on this website. :/

if you want to get totals for each item you will need a seperate array. then you can add the price into that array based on what they order.

double totalItemPrice[8] = {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00);
// in you do loop
cost += menu_list[order-1].menu_price;
totalItemPrice[order-1] += menu_list[order-1].menu_price;
// ...

now all you have to do is run through the array and any it will have the totals of each item.

Thank you. I was able to add a temp array to get further along.

This article has been dead for over six months. Start a new discussion instead.