### Pizza Store

create a program for Pizza store that will take orders from 5 variants of pizza, 5 drinks, 5 side Dishes, and 2 types of salad

program must
1. take the order from customer
2. compute the total order
3. add 10%vat to the total order
4. receive cash from the customer
5. compute the change

I've made this program but I dont know wht's wrong with this:
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277`` ``````1st Program: #include int a1=300,a2=400,a3=500,a4=700,a5=850,b1=10,b2=11,b3=12,b4=14,b5=15,c1=25,c2=35,c3=45,c4=55,c5=65,d1=45,d2=60,x,y,z,sum,cash,sum2,change,vat; int main() { cout<<"==============================="; cout<<" Menu "; cout<<"==============================="; cout<<"1--Pizza 2--Drinks "; cout<<" a1-pizza1 b1-Coke "; cout<<" a2-pizza2 b2-7up "; cout<<" a3-pizza3 b3-Sprite "; cout<<" a4-pizza4 b4-Royal "; cout<<" a5-pizza5 b5-Mountain Dew"; cout<<"3--Side Dishes 4--Salad "; cout<<" c1-side1 d1-salad1 "; cout<<" c2-side2 d2-salad2 "; cout<<" c3-side3 "; cout<<" c4-side4 "; cout<<" c5-side5 "<>x; cout<<"Piece(s):" cin>>y; z=x*y; if(x=='end') goto comp; else goto loop; comp; vat=sum*.1; sum2=vat+sum; cout<<"Cash:"; cin>>cash; change=cash-sum2; cout<<"\t\t ===="; cout<<"Total:"< int x,y,z,prod,sum,total,sum1,cash,change,total_sale; int main() { cout<<"==============================="; cout<<" Menu "; cout<<"==============================="; cout<<"1--Pizza 2--Drinks "; cout<<" a1-pizza1 b1-Coke "; cout<<" a2-pizza2 b2-7up "; cout<<" a3-pizza3 b3-Sprite "; cout<<" a4-pizza4 b4-Royal "; cout<<" a5-pizza5 b5-Mountain Dew"; cout<<"3--Side Dishes 4--Salad "; cout<<" c1-side1 d1-salad1 "; cout<<" c2-side2 d2-salad2 "; cout<<" c3-side3 "; cout<<" c4-side4 0--End of Picking"; cout<<" c5-side5 "<>y; switch(y) { case 1: cout<<"Enter your Order:"; cin>>x; cout<<"Piece(s):"; cin>>z; if(x=='a1') { prod=300*z; goto computation; } else if(x=='a2') { prod=400*z; goto computation; } else if(x=='a3') { prod=500*z; goto computation; } else if(x=='a4') { prod=700*z; goto computation; } else if(x=='a5') { prod=850*z; goto computation; } else goto loop; break; case 2: if(x=='b1') { prod=10*z; goto computation1; } else if(x=='b2') { prod=11*z; goto computation1; } else if(x=='b3') { prod=12*z; goto computation1; } else if(x=='b4') { prod=14*z; goto computation1; } else if(x=='b5') { prod=15*z; goto computation1; } else goto loop; break; case 3: if(x=='c1') { prod=25*z; goto computation3; } else if(x=='c2') { prod=35*z; goto computation3; } else if(x=='c3') { prod=45*z; goto computation3; } else if(x=='c4') { prod=55*z; goto computation3; } else if(x=='c5') { prod=65*z; goto computation3; } else goto loop; break; case 4: if(x=='d1') { prod=45*z; goto computation4; } else if(x=='d2') { prod=60*z; goto computation4; } else goto loop; break; default goto total_comp; } computation; sum=prod+0; goto loop; computation1; sum1=prod+0; goto loop; computation2; sum2=prod+0; goto loop; computation3; sum3=prod+0; goto loop; computation4; sum4=prod+0; goto loop; total_comp; total=sum+sum1+sum2+sum3+sum4; vat=total*.1; total_sale=total+vat; cout<<"\t\t ===="; cout<<"Total:"< int a1=300,a2=400,a3=500,a4=700,a5=850,b1=10,b2=11,b3=12,b4=14,b5=15,c1=25,c2=35,c3=45,c4=55,c5=65,d1=45,d2=60,x,y,z,sum,cash,sum2,change,vat; int main() { cout<<"==============================="; cout<<" Menu "; cout<<"==============================="; cout<<"1--Pizza 2--Drinks "; cout<<" a1-pizza1 b1-Coke "; cout<<" a2-pizza2 b2-7up "; cout<<" a3-pizza3 b3-Sprite "; cout<<" a4-pizza4 b4-Royal "; cout<<" a5-pizza5 b5-Mountain Dew"; cout<<"3--Side Dishes 4--Salad "; cout<<" c1-side1 d1-salad1 "; cout<<" c2-side2 d2-salad2 "; cout<<" c3-side3 "; cout<<" c4-side4 "; cout<<" c5-side5 "<>x; cout<<"Piece(s):" cin>>y; z=x*y; sum1=z+0; if(x=='end') goto comp; else goto loop; comp; vat=sum*.1; sum2=vat+sum; cout<<"Cash:"; cin>>cash; change=cash-sum2; cout<<"\t\t ===="; cout<<"Total:"<

I dont knw whats wrong with of these programs I've made so pls help me !!!
The problem is when i order again it no longer add the amount of what was previously ordered.. Thank You in advance ....
Holy spaghetti code and gratuitous global variables, Batman!
1. Don't use globals. Unless it's necessary for some reason in the project, don't do it.

2. Don't use goto. Using goto can lead to nothing but trouble (especially when it comes to debugging a problem) and is just sloppy programming. Use loops and functions instead to accomplish the same thing in a much more readable and easy to decipher format.

3. If you are using the same few lines over and over, this dictates that a function would be much more useful (and reusable) than tons of lines of code.

4. If you haven't gone over functions in your class yet, at least use loops to make this more reasonable.

Please rewrite this without any gotos and then come back if you need more help.
what does global means ?
Can you help me in making that program ? i dnt knw what should i do .... can anyone pls ?

how can I add the amount that was previously ordered on the the next order ?
Last edited on
Global variables are the ones you have declared underneath #include<iostream.h> (you should just use #include<iostream>). Declaring them within the main function would make them local and since you have no reason for global variables, it would be best to declare them there instead.

"Allyourtext\n" for a new line is better to use than "Allyourtext" << endl. Although both methods give a new line, endl flushes the stream too and can affect performance. It might not matter in this project, but later on if you get time critical projects... ;)

Are you allowed to use functions and strings in making this program? i.e. Have you covered them in class?
Last edited on
If you need those variables to not change, you can consider the following three options:

Method 1:
 ``123456789`` ``````int main(void) { const int ....; const int ....; .. .. return 0; }``````

You'll note that I only put one on each line. That improves readability.

Method 2:
 ``12345678`` ``````int main(void) { const int[] name = {x(0),x(1),..,x(n-1),x(n)}; .. .. return 0; }``````

Method 3:
 ``1234567`` ``````header.h: #define VAR1 x #define VAR2 y #define VAR3 z .. ..``````

 ``1234567891011`` ``````source.cpp: #include #include "header.h" int main(void) { .. .. return 0; }``````

For the rest of the variables (the ones that do change), you should declare them with local scope like method 1, but without the const keyword.
 ```Line 9: error: multi-character character constant Line 9: error: multi-character character constant Line 9: error: multi-character character constant Line 9: error: multi-character character constant Line 9: error: multi-character character constant Line 9: error: multi-character character constant Line 9: error: multi-character character constant Line 9: error: multi-character character constant Line 10: error: multi-character character constant Line 10: error: multi-character character constant Line 10: error: multi-character character constant Line 10: error: multi-character character constant Line 10: error: multi-character character constant Line 10: error: multi-character character constant Line 10: error: multi-character character constant In function 'int main()': Line 34: error: expected ';' before ':' token compilation terminated due to -Wfatal-errors.```

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199`` ``````#include int a1=300,a2=400,a3=500,a4=700,a5=850; int b1=10,b2=11,b3=12,b4=14,b5=15; int c1=25,c2=35,c3=45,c4=55,c5=65; int d1=45,d2=60; int o1,o2,o3,o4,o5,o6,o7,o8,o9,o10,o11,o12,o13,o14,o15,o16,o17; int p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17; int prod1,prod2,prod3,prod4,prod5,prod6,prod7,prod8,prod9,prod10,prod11,prod12,prod13,prod14,prod15,prod16,prod17; int sum,vat,total,cash,change; int main() { cout<<"\t\t==============================="; cout<<"\t\t\t Menu "; cout<<"\t\t==============================="; cout<<"\t\t1--Pizza\t\t2--Drinks\n"; cout<<"\t\t\ta1-pizza1\t\t\tb1-Coke\n"; cout<<"\t\t\ta2-pizza2\t\t\tb2-7up\n"; cout<<"\t\t\ta3-pizza3\t\t\tb3-Sprite\n"; cout<<"\t\t\ta4-pizza4\t\t\tb4-Royal\n"; cout<<"\t\t\ta5-pizza5\t\t\tb5-Mountain Dew\n"; cout<<"\t\t3--Side Dishes\t\t4--Salad\n"; cout<<"\t\t\tc1-side1\t\t\td1-salad1\n"; cout<<"\t\t\tc2-side2\t\t\td2-salad2\n"; cout<<"\t\t\tc3-side3\n"; cout<<"\t\t\tc4-side4\n"; cout<<"\t\t\tc5-side5"<>o1; cout<<"Piece(s):"; cin>>p1; prod1=o1*p1; cout<<"Enter Your Order:"; cin>>o2; cout<<"Piece(s):"; cin>>p2; prod2=o2*p2; if(o2=='end') goto comp: else { cout<<"Enter Your Order:"; cin>>o3; cout<<"Piece(s):"; cin>>p3; prod3=o3*p3; } if(o3=='end') goto comp: else { cout<<"Enter Your Order:"; cin>>o4; cout<<"Piece(s):"; cin>>p4; prod4=o4*p4; } if(o4=='end') goto comp: else { cout<<"Enter Your Order:"; cin>>o5; cout<<"Piece(s):"; cin>>p5; prod5=o5*p5; } if(o5=='end') goto comp: else { cout<<"Enter Your Order:"; cin>>o6; cout<<"Piece(s):"; cin>>p6; prod6=o6*p6; } if(o6=='end') goto comp: else { cout<<"Enter Your Order:"; cin>>o7; cout<<"Piece(s):"; cin>>p7; prod7=o7*p7; } if(o7=='end') goto comp: else { cout<<"Enter Your Order:"; cin>>o8; cout<<"Piece(s):"; cin>>p8; prod8=o8*p8; } if(o8=='end') goto comp: else { cout<<"Enter Your Order:"; cin>>o9; cout<<"Piece(s):"; cin>>p9; prod9=o9*p9; } if(o9=='end') goto comp: else { cout<<"Enter Your Order:"; cin>>o10; cout<<"Piece(s):"; cin>>p10; prod10=o10*p10; } if(o10=='end') goto comp: else { cout<<"Enter Your Order:"; cin>>o11; cout<<"Piece(s):"; cin>>p11; prod11=o11*p11; } if(o11=='end') goto comp: else { cout<<"Enter Your Order:"; cin>>o12; cout<<"Piece(s):"; cin>>p12; prod12=o12*p12; } if(o12=='end') goto comp: else { cout<<"Enter Your Order:"; cin>>o13; cout<<"Piece(s):"; cin>>p13; prod13=o13*p13; } if(o13=='end') goto comp: else { cout<<"Enter Your Order:"; cin>>o14; cout<<"Piece(s):"; cin>>p14; prod14=o14*p14; } if(o14=='end') goto comp: else { cout<<"Enter Your Order:"; cin>>o15; cout<<"Piece(s):"; cin>>p15; prod15=o15*p15; } if(o15=='end') goto comp: else { cout<<"Enter Your Order:"; cin>>o16; cout<<"Piece(s):"; cin>>p16; prod16=o16*p16; } if(o16=='end') goto comp: else { cout<<"Enter Your Order:"; cin>>o17; cout<<"Piece(s):"; cin>>p17; prod17=o17*p17; } comp: sum=prod1+prod2+prod3+prod4+prod5+prod6+prod7+prod8+prod8+prod10+prod11+prod12+prod13+prod14+prod15+prod16+prod17; vat=sum*.1; total=sum+vat; cout<<"Cash:"; cin>>cash; change=cash-total; cout<<"\t\t ====="<

i need to make my project as soon as possible so pls help me ..... im tired thinking what program should I do to make it correct ..... T.T

i cnt stop using goto coz i dnt know what will i do ... so pls help me ..... credit to all ..... T.T
Holy crap. Okay, look at the following:

Iteration structures in here:
http://www.cplusplus.com/doc/tutorial/control/

Scope in here:
http://www.cplusplus.com/doc/tutorial/variables/

This entire article:
http://www.cplusplus.com/doc/tutorial/arrays/

And these:
http://www.cplusplus.com/doc/tutorial/functions/
http://www.cplusplus.com/doc/tutorial/functions2/

There is way too much in that homework spam up there for us to really help you with unless we literally do it for you, and I'm not up for doing that right now.
I'm not that good with pointers so can someone clean up my code if there's anything wrong?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259`` ``````#include #include #include using namespace std; void show_menu() { cout << "Here's our menu: \n"; cout << "Pizzas: \t Drinks: \n"; cout << "\t Pizza_1 \t Drink_1 \n"; cout << "\t Pizza_2 \t Drink_2 \n"; cout << "\t Pizza_3 \t Drink_3 \n"; cout << "\t Pizza_4 \t Drink_4 \n"; cout << "\t Pizza_5 \t Drink_5 \n"; cout << "Side Dishes: \t Salads: \n"; cout << "\t Side_1 \t Salad_1 \n"; cout << "\t Side_2 \t Salad_2 \n"; cout << "\t Side_3 \n"; cout << "\t Side_4 \n"; cout << "\t Side_5 \n"; } int choose_pizza(int pchoice) { for(;;) { cout << "What pizza would you like? [1-5]: \n"; cin >> pchoice; if(1 <= pchoice && pchoice <= 5) { break; } else { cout << "Please enter 1 - 5\n"; } } return pchoice; } int choose_drink(int dchoice) { for(;;) { cout << "What drink would you like? [1-5]: \n"; cin >> dchoice; if(1 <= dchoice && dchoice <= 5) { break; } else { cout << "Please enter 1 - 5\n"; } } return dchoice; } int choose_side(int cchoice) { for(;;) { cout << "What side dish would you like? [1-5]: \n"; cin >> cchoice; if(1 <= cchoice && cchoice <= 5) { break; } else { cout << "Please enter 1 - 5\n"; } } return cchoice; } int choose_salad(int schoice) { for(;;) { cout << "What salad would you like? [1-2]: \n"; cin >> schoice; if(1 <= schoice && schoice <= 2) { break; } else { cout << "Please enter 1 - 2\n"; } } return schoice; } void show_choices(char cpizza, char cdrink, char csdish, char csalad, int * pchoice, int * dchoice, int * cchoice, int * schoice) { cout << "Would you like a pizza? (Y/N): \n"; cin >> cpizza; switch(cpizza) { case 'y': case 'Y': *pchoice = choose_pizza(*pchoice); break; case 'n': case 'N': break; default: cout << "No answer? OK...\n"; } cout << "Would you like a drink? (Y/N): \n"; cin >> cdrink; switch(cdrink) { case 'y': case 'Y': *dchoice = choose_drink(*dchoice); break; case 'n': case 'N': break; default: cout << "No answer? OK...\n"; } cout << "Would you like a side dish? (Y/N): \n"; cin >> csdish; switch(csdish) { case 'y': case 'Y': *cchoice = choose_side(*cchoice); break; case 'n': case 'N': break; default: cout << "No answer? OK...\n"; } cout << "Would you like a salad? (Y/N): \n"; cin >> csalad; switch(csalad) { case 'y': case 'Y': *schoice = choose_salad(*schoice); break; case 'n': case 'N': break; default: cout << "No answer? OK...\n"; } } double calculate(double total, double sub_total, int pchoice, int dchoice, int cchoice, int schoice) { switch(pchoice) { case 1: sub_total += 3; break; case 2: sub_total += 4; break; case 3: sub_total += 5; break; case 4: sub_total += 7; break; case 5: sub_total += 8.5; break; } switch(dchoice) { case 1: sub_total += .1; break; case 2: sub_total += .11; break; case 3: sub_total += .12; break; case 4: sub_total += .14; break; case 5: sub_total += .15; break; } switch(cchoice) { case 1: sub_total += .25; break; case 2: sub_total += .35; break; case 3: sub_total += .45; break; case 4: sub_total += .55; break; case 5: sub_total += .65; break; } switch(schoice) { case 1: sub_total += .45; break; case 2: sub_total += .60; break; } total = sub_total * .1 + sub_total; return total; } void show_receipt(double total) { cout << "Your total is: \$" << total << "\n"; } int main(int nNumberofArgs,char* pszArgs[]) { char cpizza, cdrink, csdish, csalad, order; int pchoice = 0, dchoice = 0, cchoice = 0, schoice = 0; double sub_total = 0, total = 0; int * ppointer = &pchoice; int * dpointer = &dchoice; int * cpointer = &cchoice; int * spointer = &schoice; for(;;) { show_menu(); show_choices(cpizza, cdrink, csdish, csalad, ppointer, dpointer, cpointer, spointer); total = calculate(total, sub_total, pchoice, dchoice, cchoice, schoice); show_receipt(total); cout << "Would you like to order again? (Y/N): \n"; cin >> order; switch(order) { case 'y': case 'Y': break; case 'n': case 'N': system("PAUSE"); return 0; default: break; } } }``````
`void show_choices(char cpizza, char cdrink, char csdish, char csalad, int * pchoice, int * dchoice, int * cchoice, int * schoice)`
Look through this line and the function that's under it. If you have any variables that aren't used in the function, don't pass them around. It makes your overhead higher, but more importantly for you, it will tend to confuse people that are trying to read the code, including yourself.

 ``1234`` `````` int * ppointer = &pchoice; int * dpointer = &dchoice; int * cpointer = &cchoice; int * spointer = &schoice;``````

These are decent, but you really need to make them more descriptive. A huge part of programming is re-reading your code, and having variable (or pointer) names that don't tell you what they're supposed to do just with their name is not going to help you debug.

`int choose_pizza(int pchoice)`
All of the functions like this don't need a variable passed to them. Just declare a variable in local scope. It'll make things cleaner, and you can even name the whole lot of them tmp, since they will never interact with each other. That will make it so that these lines:
` *pchoice = choose_pizza(*pchoice);`
don't actually need to have a variable passed, and so you'll lose the complexity of trying to deal with that pointer at least.

`int main(int nNumberofArgs,char* pszArgs[])`
You don't have to, if you don't want to, but normally these variables are actually named argc and argv, respectively.
Topic archived. No new replies allowed.