Can anyone tell me how to improve this program?

Can anyone help me to improve this program? So please feel free to correct me or tell me what I'm doing wrong.
Thanks!

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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include <iostream>
#include <string>

using namespace std;

int multiply (int a,int b)
{
int r;
r=a*b;
return(r);
}
int subtract (int a,int b)
{
int r;
r=a-b;
return (r);
}

void beverages()
{
cout<<"Beverages"<<endl<<endl;
cout<<"Coke - 12"<<endl;
cout<<"Sprit - 12"<<endl;
cout<<"Coffee - 5"<<endl;
}
void snacks()
{
cout<<"Snacks"<<endl;
cout<<"Sandwich - 15"<<endl<<endl;
cout<<"Hamburger - 15"<<endl;
cout<<"Spagetti - 15"<<endl;
}

int main()
{
int drinks[2];
drinks[0]=12;
drinks[1]=12;
drinks[2]=5;

int snack[2];
snack[0]=15;
snack[1]=15;
snack[2]=15;

int choice;
int choice_2;
int cost;
int quantity;
int total=0;
int cash;
int change;
char more;

again:
snacks();
cout<<endl;
beverages();
cout<<endl;
cout<<"Choice:"<<endl;
cout<<"1. Snacks"<<endl; cout<<"2. Beverages"<<endl<<endl;
cout<<"Please place your order:";
cin>>choice;


while (true)
{
    if (choice==1)
    {
    system("cls");
    snacks();
    cout<<endl;
    cout<<"Select your choice:";
    cin>>choice_2;
        if (choice_2==1)
        {
      cout<<"Quantity:";
      cin>>quantity;
      cout<<endl;
      cout<<"Cost:";
      cost=multiply(snack[0],quantity);
      total=total+cost;
      cout<<cost<<endl;
      break;
      }else if (choice_2==2)
      {
      cout<<"Quantity:";
      cin>>quantity;
      cout<<endl;
      cout<<"Cost:";
      cost=multiply(snack[1],quantity);
      total=total+cost;
      cout<<cost<<endl;
      break;
      }else if (choice_2==3)
      {
      cout<<"Quantity:";
      cin>>quantity;
      cout<<endl;
      cout<<"Cost:";
      cost=multiply(snack[2],quantity);
      total=total+cost;
      cout<<cost<<endl;
      break;
      }
   }
   else if (choice==2)
       {
      system("cls");
        beverages();
        cout<<endl;
        cout<<"Select your choice:";
        cin>>choice_2;
      if (choice_2==1)
      {
      cout<<"Quantity:";
      cin>>quantity;
      cout<<endl;
      cost=multiply(drinks[0],quantity);
      total=total+cost;
      cout<<"Cost:";
      cout<<cost<<endl;
      break;
      }else if (choice_2==2)
      {
      cout<<"Quantity:";               
      cin>>quantity;
      cout<<endl;
      cost=multiply(drinks[1],quantity);
      total=total+cost;
      cout<<"Cost:";
      cout<<cost<<endl;
      break;
      }else if (choice_2==3)
      {
      cout<<"Quantity:";
      cin>>quantity;
      cout<<endl;
      cost=multiply(drinks[3],quantity);
      total=total+cost;
      cout<<"Cost:";
      cout<<cost<<endl;
      break;
      }
   }
}

cout<<"Do you want to try again?(y/n)";
cin>>more;
if (more=='y'||more=='Y')
{
system ("cls");
goto again;
}else if (more=='n'||more=='N')
{

cout<<"The total amount you bought is "<<total<<endl;
cout<<"Please enter payment:";
cin>>cash;
cout<<endl;
do
{
system ("cls");
cout<<"Sorry the amount you entered is incorrect"<<endl;
cout<<"Please try again"<<endl;
cout<<endl;
cout<<"The total amount you bought is "<<total<<endl;
cout<<"Please enter payment:";
cin>>cash;
cout<<endl;
}while (cash>total);

change=subtract(cash,total);
cout<<"Your change:"<<change<<endl;

}
cout<<"...Please press ENTER..."<<endl;
cin.ignore(2);
return 0;
}


This part of the code still has problems so if anyone has any opinions I'd be very thankfull.


cout<<"Do you want to try again?(y/n)";
cin>>more;
if (more=='y'||more=='Y')
{
system ("cls");
goto again;
}else if (more=='n'||more=='N')
{

cout<<"The total amount you bought is "<<total<<endl;
cout<<"Please enter payment:";
cin>>cash;
cout<<endl;
do
{
system ("cls");
cout<<"Sorry the amount you entered is incorrect"<<endl;
cout<<"Please try again"<<endl;
cout<<endl;
cout<<"The total amount you bought is "<<total<<endl;
cout<<"Please enter payment:";
cin>>cash;
cout<<endl;
}while (cash>total);

change=subtract(cash,total);
cout<<"Your change:"<<change<<endl;

}
Your functions are pretty useless to be honest, subtract and add are a waste of time, and the printing ones are kind of worthless IMHO. You are going 1 too many on your arrays (int something[2] has 2 elements, [0] and [1] ONLY).

Use more indentation, your code is quite difficult to read (at least your main function is).

Don't use goto...it's not needed here. Use a loop. And add some useful functions, like a "Select your choice" function or something.
Make it actually give me a snack and/ or a beverage.
Topic archived. No new replies allowed.