Function not working correctly

Well, i'm back... already. Have to expand on the previous program and make it accomodate 3 users. This is what I have so far. The first two methods appear to work, apparently between the second and third one is where the problem is.

http://i.imgur.com/w1JMatg.png

After it's spiel about denominations and its purpose, it's supposed to (as you can see in the code below)

ask everyone how many bills they have. I know there's no provision of adding them all together (yet) but I'll cross that bridge when I come to it. It never asks them, it just skips to the end as you can see in the image and only saves one name. I know I only gave Name = GetName() and not Name2 = GetName() but when I did that it would run the the methods multiple times, which I did not want, naturally. Thanks in advance for your help.

Had to cut a chunk of the code out due to this forums max character limit, just the function TotalAmount's 3rd name spot, you get the point from two of them i'm sure, lol.
Last edited on
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336

#include <iostream>
#include <string>

using namespace std;

int NumberUsers()
{
	int Users;

	cout << "How many users will enter their data today? (1 or 3)" << endl;
	cin >> Users;

	return(Users);

}

string GetName(int Users)
{


	string inputName;
	string inputName2;
	string inputName3;

	if (Users == 1)
	{
		cout << "Hello, please enter your name." << endl;
		cin >> inputName;
		cout << inputName << endl;
		cout << "This program is used for counting money, specifically bills in denominations of $1, $2, $5, $10, $20, $50, and $100." << endl;

		return(inputName);
	}
	if (Users == 3)
	{
		cout << "Hello, please enter your name, person 1." << endl;
		cin >> inputName;
		cout << "Person 2." << endl;
		cin >> inputName2;
		cout << "Person 3." << endl;
		cin >> inputName3;
		cout << "Welcome, "; cout << inputName; cout << ", "; cout << inputName2; cout << " and "; cout << inputName3 << endl;
		cout << "This program is used for counting money, specifically bills in denominations of $1, $2, $5, $10, $20, $50, and $100." << endl;

		return(inputName, inputName2, inputName3);

	}
}


int TotalAmount(string Name, string Name2, string Name3, int Users)
{

	int TotalMoney;

	int Bills1; //numbers of bills
	int Bills2;
	int Bills5;
	int Bills10;
	int Bills20;
	int Bills50;
	int Bills100;
	int Bills1b;
	int Bills2b;
	int Bills5b;
	int Bills10b;
	int Bills20b;
	int Bills50b;
	int Bills100b;
	int Bills1c;
	int Bills2c;
	int Bills5c;
	int Bills10c;
	int Bills20c;
	int Bills50c;
	int Bills100c;
	int NumberOnes; //total amount of money of bills, i.e. 100 $1 bills = $100.
	int NumberTwos;
	int NumberFives;
	int NumberTens;
	int NumberTwenties;
	int NumberFifties;
	int NumberHundreds;
	int NumberOnesB;
	int NumberTwosB;
	int NumberFivesB;
	int NumberTensB;
	int NumberTwentiesB;
	int NumberFiftiesB;
	int NumberHundredsB;
	int NumberOnesC;
	int NumberTwosC;
	int NumberFivesC;
	int NumberTensC;
	int NumberTwentiesC;
	int NumberFiftiesC;
	int NumberHundredsC;

	if (Users == 1)
	{
		cout << "How many $1 bills do you have, "; cout << Name; cout << "?" << endl;
		cin >> Bills1;

		if (Bills1 < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills1;
		}

		cout << "How many $2 bills do you have, "; cout << Name; cout << "?" << endl;
		cin >> Bills2;

		if (Bills2 < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills2;
		}

		cout << "How many $5 bills do you have, "; cout << Name; cout << "?" << endl;
		cin >> Bills5;

		if (Bills5 < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills5;
		}

		cout << "How many $10 bills do you have, "; cout << Name; cout << "?" << endl;
		cin >> Bills10;

		if (Bills10 < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills10;
		}

		cout << "How many $20 bills do you have, "; cout << Name; cout << "?" << endl;
		cin >> Bills20;

		if (Bills20 < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills20;
		}

		cout << "How many $50 bills do you have, "; cout << Name; cout << "?" << endl;
		cin >> Bills50;

		if (Bills50 < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills50;
		}

		cout << "How many $100 bills do you have, "; cout << Name; cout << "?" << endl;
		cin >> Bills100;

		if (Bills100 < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills100;
		}
		
	}
	
	if (Users == 3)
	{
		cout << "How many $1 bills do you have, "; cout << Name; cout << "?" << endl;
		cin >> Bills1b;

		if (Bills1b < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills1b;
		}

		cout << "How many $2 bills do you have, "; cout << Name; cout << "?" << endl;
		cin >> Bills2b;

		if (Bills2b < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills2b;
		}

		cout << "How many $5 bills do you have, "; cout << Name; cout << "?" << endl;
		cin >> Bills5b;

		if (Bills5b < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills5b;
		}

		cout << "How many $10 bills do you have, "; cout << Name; cout << "?" << endl;
		cin >> Bills10b;

		if (Bills10b < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills10b;
		}

		cout << "How many $20 bills do you have, "; cout << Name; cout << "?" << endl;
		cin >> Bills20b;

		if (Bills20b < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills20b;
		}

		cout << "How many $50 bills do you have, "; cout << Name; cout << "?" << endl;
		cin >> Bills50b;

		if (Bills50b < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills50b;
		}

		cout << "How many $100 bills do you have, "; cout << Name; cout << "?" << endl;
		cin >> Bills100b;

		if (Bills100b < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills100b;
		}

		cout << "How many $1 bills do you have, "; cout << Name2; cout << "?" << endl;
		cin >> Bills1c;

		if (Bills1c < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills1c;
		}

		cout << "How many $2 bills do you have, "; cout << Name2; cout << "?" << endl;
		cin >> Bills2c;

		if (Bills2c < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills2c;
		}

		cout << "How many $5 bills do you have, "; cout << Name2; cout << "?" << endl;
		cin >> Bills5c;

		if (Bills5c < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills5c;
		}

		cout << "How many $10 bills do you have, "; cout << Name2; cout << "?" << endl;
		cin >> Bills10c;

		if (Bills10c < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills10c;
		}

		cout << "How many $20 bills do you have, "; cout << Name2; cout << "?" << endl;
		cin >> Bills20c;

		if (Bills20c < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills20c;
		}

		cout << "How many $50 bills do you have, "; cout << Name2; cout << "?" << endl;
		cin >> Bills50c;

		if (Bills50c < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills50c;
		}

		cout << "How many $100 bills do you have, "; cout << Name2; cout << "?" << endl;
		cin >> Bills100c;

		if (Bills100c < 0)
		{
			cout << "Sorry, you have entered an invalid integer, please try again." << endl;
			cin >> Bills100c;
		}

		cout << "How many $1 bills do you have, "; cout << Name3; cout << "?" << endl;
		cin >> Bills1;

	}

	NumberOnes = Bills1 * 1;
	NumberTwos = Bills2 * 2;
	NumberFives = Bills5 * 5;
	NumberTens = Bills10 * 10;
	NumberTwenties = Bills20 * 20;
	NumberFifties = Bills50 * 50;
	NumberHundreds = Bills100 * 100;

	TotalMoney = NumberOnes + NumberTwos + NumberFives + NumberTens + NumberTwenties + NumberFifties + NumberHundreds;

	return(TotalMoney);
}
int main()
{
	string Name;
	string Name2;
	string Name3;
	int TotalMoney;
	int NumUsers;
	
	NumUsers = NumberUsers();
	Name = GetName(NumUsers);
	TotalMoney = 0;



	DisplayMoney(TotalMoney, Name, Name2, Name3, NumUsers);
	ThankYouMsg(Name, Name2, Name3, NumUsers);
	TotalMoney = TotalAmount(Name, Name2, Name3, NumUsers);




	system("PAUSE");

	return(0);
}
Topic archived. No new replies allowed.