making a restaurant bill in c++

Hello there
this is my first post, i'm a beginner in c++
I'm making a project about restaurant in c++ and i'm having a problem
i want the customer to enter how many meals he wants to order then enter the meal number he wants to order
after that the program will take the value that i assigned to each meal and make a bill to it then inputs the bill only
the program runs and shows the menu , but after i enter a meal number it doesn't do anything
this is the code i tried making:
using MS visual studio 2010 express
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
 #include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int omlete=16, crepe=28, pancakes=10, doughnuts=4, zaatar_croissant=8 , cheese_croissant=11;
	int custOrder1;
	int mealNum1;
	cout<< " ************************************ \n " ;
	cout<< " * breakfast menu : * \n";
	cout<< " * 1- Omlete " << setw(20) << " 2- Crepe *" << endl;
	cout<< " * 3- Cheese Croissant" << setw(20)<< " 4- Zaatar Croissant *" << endl;
	cout<< " * 5- Pancakes" << setw(20) << " 6- Doughnuts *" << endl;
	cout<< " ************************************ \n " ;
	cout<< " * How many meal you would like to order? *" << endl;
	cin>> mealNum1;
	cout<< "enter a meal number:" << endl;
	cin>> custOrder1; 
	while (custOrder1 != 0) 
	{
			for (int counter=0; counter>0; counter++)
		{
			int bill;
				cin>> custOrder1;
					custOrder1++;
					bill=custOrder1;
		}
	}
return custOrder1;
}


can you help me?
Last edited on
Morning dude.

This line:
for (int counter = 0; counter > 0; counter++)
in words is "set counter to zero and loop while counter is greater than zero".

So it won't loop at all as it's never meets the condition.

i believe you want something more like:
for (int counter = 0; counter < mealNum1; counter++)
Last edited on
Try this.
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
 #include<iostream>
#include<iomanip>
#include <string>
using namespace std;

int main()
{
	const int ITEMS = 6;
	string meals[ITEMS] = {"omlete", "crepe", "pancakes","doughnuts", "zaatar_croissant" , "cheese_croissant"};
	int prices[ITEMS] = {16,28,10,4,8,11};
	int orders[ITEMS] = {0};
	int orderNum;
	int n;	//number of meals to order
	int totalCost = 0;
	
	cout<<endl<<endl<<"\t\t\tMenu"<<endl<<endl;
	for(int i = 0; i < ITEMS; i++)
	{
		if(i%2 == 0) 
			cout<<endl;
		cout<<i+1<<" - "<<setw(15)<<meals[i]<<"\t";
	}
	
	cout<<endl<<endl<<"How many meal you would like to order? "<< endl;
	cin>>n;
	
	for(int i = 0; i < n; i++)
	{
		cout<<"Enter item "<<i+1<<" : ";
		cin>>orderNum;
		totalCost += prices[orderNum-1];
		orders[orderNum -1] = 1;
	}
	
	cout<<endl<<"Your bill is "<<endl<<endl;
	
	cout<<setw(15)<<"Meal item"<<"  "<<setw(5)<<"Price"<<endl;
	cout<<"-----------------------"<<endl;
	for(int i = 0; i < ITEMS; i++)
	{
		if(orders[i] == 1)
			cout<<setw(15)<<meals[i]<<"   "<<setw(3)<<prices[i]<<endl;
	}
	cout<<endl<<"\t\t"<<"Total : "<<totalCost<<endl;
	
	return 0;
}
mutexe
Thanks, I didn't realize that while making the program

shadowCODE
Using an array surly made it easier & it worked, thanks for your great help.
Last edited on
hey shadowCODE
Could you explain this to me ?
1
2
3
4
5
6
7
8
 
for(int i = 0; i < n; i++)
	{
		cout<<"Enter item "<<i+1<<" : ";
		cin>>orderNum;
		totalCost += prices[orderNum-1];
		orders[orderNum -1] = 1;
	} 


specially this line :
1
2
totalCost += prices[orderNum-1];
		orders[orderNum -1] = 1;
Last edited on
1
2
3
string meals[ITEMS] = {"omlete", "crepe", "pancakes","doughnuts", "zaatar_croissant" , "cheese_croissant"};
int prices[ITEMS] = {16,28,10,4,8,11};
int orders[ITEMS] = {0};

Every meal and corresponding price has the same index in their respective arrays.

Now
1
2
3
4
5
6
7
8
9
10
for(int i = 0; i < n; i++)
{
	cout<<"Enter item "<<i+1<<" : ";
	cin>>orderNum;  //Enter order Numer. (e.g 4)
	totalCost += prices[orderNum-1];    //adding the price of each meal to the total cost
/*     since 4 is doughnuts which is in index 3 of the meals array, then the prices is also in index 3 of the price array. 
         so you add its price to the total price.
*/
	orders[orderNum -1] = 1;  //to keep track of the meals ordered.
}


Do you acutally have a problem understanding the code totalCost += prices[orderNum-1]; or the its implementation in this problem??
shadowCODE
It worked but i wanted to understand how it worked
thanks
Topic archived. No new replies allowed.