Gross_total wrong...

everything works and calculates except the Gross_total. I don't know what is wrong with it. Help please!

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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
  /************************************************************/
/* FILENAME : program5.cpp                                  */
/* PROGRAMMER: Amy Langdon                                  */
/* PURPOSE : To track ticket sales for Summerville SeaWorld */
/************************************************************/


#include <stdio.h>
#include <iostream>
#include <time.h>
#include <string>
#include <iomanip>
using namespace std;

int main() 
{

  int SEAT_COUNT;
  int MAX_SEAT_COUNT = 25;
  int option;
  int Total_Sold = 0;
  int not_for_toddlers;
  int not_for_juniors;
  int not_for_adults;
  int TODDLERS = 0;
  int JUNIORS = 0;
  int ADULTS = 0;
  double price;
  double discount;
  double Gross_total = 0.0;
  char coupon;

  SEAT_COUNT = MAX_SEAT_COUNT;

  cout << "Summerville SeaWorld Ticket Sales v1.01\n";
  
  while(SEAT_COUNT >=0 )
  {
  	cout << "\nSummerville SeaWorld Ticket Menu\n";
  	cout << "----------\n";
  	cout << "1. Toddlers\n";
  	cout << "2. Juniors\n";
  	cout << "3. Adults\n";
  	cout << "4. Quit\n";
  	cout << "Enter your option ";
  	cin >> option;

  switch(option)
	{
		case 1:
			cout << "How many tickets do you want for toddlers?\n";
			cin >> not_for_toddlers;
			
			if(not_for_toddlers <= 10)
			{
				SEAT_COUNT = SEAT_COUNT - not_for_toddlers;

				cout <<"\nWelcome to Summerville SeaWorld\n";				
				cout <<"-------------------------------\n";
				cout <<"\nThe total for these tickets is $0.00\n";
				cout << "------------------------------------------\n";

				TODDLERS = TODDLERS + not_for_toddlers;
				Total_Sold = Total_Sold + not_for_toddlers;
				system("pause");
				break;
			}
	
			else
			{
	
				cout <<"You are only allowed 10 tickets\n";

				SEAT_COUNT = SEAT_COUNT - 10;

				cout <<"\nWelcome to Summerville SeaWorld\n";				
				cout <<"-------------------------------\n";
				cout <<"\nThe total for these tickets is $0.00\n";
				cout << "------------------------------------------\n";

				TODDLERS = TODDLERS + 10;
				Total_Sold = Total_Sold + 10;
				system("pause");
				break;
			}

		case 2:

			cout << "How many tickets do you want for juniors?\n";
			cin >>not_for_juniors;

			if(not_for_juniors <= 10)
			{
				SEAT_COUNT = SEAT_COUNT - not_for_juniors;
				price = not_for_juniors * 7.50;
				JUNIORS = JUNIORS +  not_for_juniors;
				Total_Sold = Total_Sold + not_for_juniors;

				cout << "\nDo you have a discount coupon? (y/n) \n";
				cin >> coupon;

				if('y'== coupon)
				{

					discount = price * 0.25;
					price = price - discount;
					
					cout.precision( 2 );
					cout <<"\nWelcome to Summerville SeaWorld\n";
					cout << "------------------------------------------\n";
					cout << "Your total discount is $"<<discount<<"\n";
					cout << "\nYour total amount after the discount is $"<<price<<"\n";
					cout << "------------------------------------------\n";

					Gross_total = Gross_total + price;
					
					system("pause");
					break;
				}

				else
				{
					cout.precision( 2 );
					cout <<"\nWelcome to Summerville SeaWorld\n";
					cout << "------------------------------------------\n";
					cout << "\nYour total amount is $"<<price;
					cout << "------------------------------------------\n";

					Gross_total = Gross_total + price;
					
					system("pause");
					break;
				}
			}
	
			else
			{

				cout <<"You are only allowed 10 tickets\n";
				
				SEAT_COUNT = SEAT_COUNT - 10;
				price = 10 * 7.50;
				JUNIORS = JUNIORS + 10;
				Total_Sold = Total_Sold + 10;

				cout << "\nDo you have a discount coupon? (y/n) \n";
				cin >> coupon;

				if('y'== coupon)
				{

					discount = price * 0.25;
					price = price - discount;

					cout.precision( 2 );
					cout <<"\nWelcome to Summerville SeaWorld\n";
					cout << "------------------------------------------\n";
					cout << "Your total discount is $"<<discount<<"\n";
					cout << "\nYour total amount after the discount is $" <<price<<"\n";
					cout << "------------------------------------------\n";

					Gross_total = Gross_total + price;
					
					system("pause");
					break;
				}

				else
				{
					cout.precision( 2 );
					cout <<"\nWelcome to Summerville SeaWorld\n";
					cout << "------------------------------------------\n";
					cout << "\nYour total amount is $"<<price;
					cout << "------------------------------------------\n";

					Gross_total = Gross_total + price;
					
					system("pause");
					break;
				}
				break;
			}

		case 3:

			cout << "How many tickets do you want for adults?\n";
			cin >>not_for_adults;

			if(not_for_adults <= 10)
			{

				SEAT_COUNT = SEAT_COUNT - not_for_adults;
				price = not_for_adults * 11.50;
				ADULTS = ADULTS + not_for_adults;
				Total_Sold = Total_Sold + not_for_adults;

				cout << "Do you have a discount coupon? (y/n) \n";
				cin >> coupon;

				if('y'==coupon)
				{

					discount= price * 0.25;
					price = price - discount;

					cout.precision( 2 );
					cout <<"\nWelcome to Summerville SeaWorld\n";
					cout << "------------------------------------------\n";
					cout << "Your total discount is $"<<discount<<"\n";
					cout << "\nYour total amount after the discount is $" <<price<<"\n";
					cout << "------------------------------------------\n\n";

					Gross_total = Gross_total + price;
					
					system("pause");
					break;
				}

				else
				{

					cout.precision( 2 );
					cout <<"\nWelcome to Summerville SeaWorld\n";
					cout << "------------------------------------------\n";
					cout << "Your total amount is $"<<price<<"\n";
					cout << "------------------------------------------\n";

					Gross_total = Gross_total + price;
					
					system("pause");
					break;
				}
			}

			else
			{

				cout <<"You are only allowed 10 tickets\n";
				
				SEAT_COUNT = SEAT_COUNT - 10;
				price = 10 * 11.50;
				ADULTS = ADULTS + 10;
				Total_Sold = Total_Sold + 10;

				cout << "\nDo you have a discount coupon? (y/n) \n";
				cin >> coupon;

				if('y'== coupon)
				{

					discount = price * 0.25;
					price = price - discount;

					cout.precision( 2 );
					cout <<"\nWelcome to Summerville SeaWorld\n";
					cout << "------------------------------------------\n";
					cout << "Your total discount is $"<<discount<<"\n";
					cout << "\nYour total amount after the discount is $" <<price<<"\n";
					cout << "------------------------------------------\n";

					Gross_total = Gross_total + price;
					
					system("pause");
					break;
				}

				else
				{
					cout.precision( 2 );
					cout <<"\nWelcome to Summerville SeaWorld\n";
					cout << "------------------------------------------\n";
					cout << "\nYour total amount is $"<<price<<"\n";
					cout << "------------------------------------------\n";

					Gross_total = Gross_total + price;
					
					system("pause");
					break;
				}
				break;
	
			}

		case 4:

			cout << "Quit";
			return 0;

		default:

			cout << "Please enter a valid option\n";
	}
	

	
     }
    	

	time_t now = time(0);
	tm* localtm = localtime(&now);

	//printf("It's %.24s.\n", ctime_s(&now));
  	cout <<"***************************************\n";
  	cout << "TICKET SALES REPORT FOR DATE:"<< asctime(localtm)<<"\n" ;
  	cout <<"---------------------------------------\n";
  	cout << "SEAT CAPACITY \t EXTRA \t TOTAL SOLD\n";
  	cout <<"---------------------------------------\n";
  	cout <<MAX_SEAT_COUNT<<"\t\t"<<(Total_Sold-MAX_SEAT_COUNT)<<"\t\t"<<Total_Sold<<"\n";
  	cout <<"---------------------------------------\n";
  	cout << "TODDLERS \tJUNIORS \tADULTS \n";
  	cout <<"---------------------------------------\n";
  	cout <<  TODDLERS<<"\t\t"<<JUNIORS<<"\t\t"<<ADULTS<<"\n";
  	cout <<"---------------------------------------\n";
  	cout << "GROSS FOR TODAY: $"<<Gross_total<<"\n";
  	cout <<"***************************************\n";


}
I suggest running your app in a debugger. That way, you'll be able to see what's going on, which lines of code are being executed, and what values are being calculated.
I am using Visual Basic and debugging it, but I don't know where to look to see what you are talking about.
I assume you mean Visual Studio?

A quick Google search for "c++ debugging tutorial" should provide some useful links to get you started.
@aflangdon

Just some style points.

First is your variable names - one could directly interpret not_for_toddlers as meaning "Not for toddlers", rather than "Number of tickets for toddlers".

You have a lot of repetition in your code. Lines 102 -119 & 122 - 134 for example is repeated 4 times which is 126 LOC.

So these should be in functions.

In general switch cases should call functions if they are more than a small amount of code.

There is a bit of an unwritten rule that a function (including main) should not be more than 80 LOC - some even go for 20 - 40 LOC.

Check out the assignment operators += and -= and *=, plus others. They can be used like this, for example:

Gross_total += price;

These operators are good because they save on typos and shorten up the code a bit.

Hope this helps.
Topic archived. No new replies allowed.