ATM Code

Hi guys, please take a look at my code.
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
#include<iostream.h>
#include<conio.h>
#include<string.h>
main(){
	clrscr();
	char  name[100],c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16;
	float balance,deposit;
	cout<<"Enter your name:";
	cin>>name;
	cout<<"\nHello "<<name<<"! Welcome to BPSU Online Banking System.";
	cout<<"\nThank you for creating an account with us. To better serve you, please provide us the following information.";
loop:
	cout<<"\n\nAccount Type:";
	cout<<"\n[S]avings";
	cout<<"\n[C]hecking";
	cout<<"\nEnter your choice:";
	cin>>c1;
	switch (c1)
	{
	 case 'S':
	 case 's':
		cout<<"Thank you for choosing a savings account.";
		break;

	 case 'C':
	 case 'c':
		cout<<"Thank you for choosing a checking account.";
		break;
	 default:
		cout<<"Your choice is invalid.";

	}
	 if(c1 == 'c' && 'C')
		{
     icloop:	cout<<"\nPlease input your initial balance:";
		cin>>balance;
		if(balance>=10000)
		{
			cout<<"\nThank you for opening an account with us!";
			cout<<"\nWould you like to have another transaction?[y/n]";
		}
		else
		{
		cout<<"\nYou have entered a balance that is below the minimum initial balance for a checking account. Please input an amount greater than or equal to 10000!";
		}
		}

	if(c1 == 's' && 'S')
		{
     isloop:	cout<<"\nPlease input your initial balance:";
		cin>>balance;
		if(balance>=5000)
		{
			cout<<"\nThank you for opening an account with us!";

			cout<<"\nWould you like to have another transaction? [y/n]";

		}
		else
		{    cout<<"\nYou have entered a balance that is below the minimum initial balance for a savings account. Please input an amount greater than or equal to 5000!";
		goto loop;
		}
	cin>>c2;
	switch (c2)
	{
	 case 'Y':
	 case 'y':
mainmenu:	clrscr();
		cout<<"BPSU Online Banking System Main Menu";
		cout<<"\n\n[B]alance Inquiry";
		cout<<"\n[D]eposit";
		cout<<"\n[W]ithdraw";
		cout<<"\n[E]xit";
		cout<<"\nEnter your choice:";
		cin>>c3;
		switch(c3)
		{
		  case 'B':
		  case 'b':
			clrscr();
			cout<<"Balance Inquiry";
			if(c3 == 'c' && 'C')
			{
			cout<<"\n\nAccount Type:Checking Account";
			}
			else if(c3 == 'S' && 's')
			{
			cout<<"\n\nAccount Type:Savings Account";
			}
			cout<<"\nCurrent Balance:"<<balance<<"";
			cout<<"\nWould you like to do another transaction? [y/n]";
			cin>>c4;
			switch(c4)
			{
				case 'Y':
				case 'y':
					goto mainmenu;

				case 'N':
				case 'n':
					cout<<"\nThank you for banking with us!";
					break;
			}


		  case 'D':
		  case 'd':
			clrscr();
			cout<<"Deposit an Amount";
			cout<<"\n\nPlease choose how much you want to deposit:";
			cout<<"\n[5]00";
			cout<<"\n[1]000";
			cout<<"\n[2]000";
			cout<<"\n[50]00";
			cout<<"\n[O]ther:";
			cin>>c5;
			switch(c5)
			{
				case '5':
				     balance =balance + 500;
				     cout<<"\nThank you for updating your account!";
				     cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c6;
				      switch(c6)
				      {
					case 'Y':
					case 'y':
						goto mainmenu;


					case 'N':
					case 'n':
						cout<<"\nThank you for banking with us!";
						break;
					}
				case '1':
				     balance =balance + 1000;
				     cout<<"\nThank you for updating your account!";
				     cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c7;
				      switch(c7)
				      {
					case 'Y':
					case 'y':
						goto mainmenu;

					case 'N':
					case 'n':
						cout<<"\nThank you for banking with us!";
						break;
					}
				case '2':
				     cout<<"\nThank you for updating your account!";
				     balance =balance + 2000;
				     cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c8;
				      switch(c8)
				      {
					case 'Y':
					case 'y':
						goto mainmenu;

					case 'N':
					case 'n':
						cout<<"\nThank you for banking with us!";
						break;
					}
				case '50':
				     cout<<"\nThank you for updating your account!";
				     balance =balance + 5000;
				     cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c9;
				      switch(c9)
				      {
					case 'Y':
					case 'y':
						goto mainmenu;

					case 'N':
					case 'n':
						cout<<"\nThank you for banking with us!";
						break;
					}
				case 'O':
				case 'o':
				      cout<<"\n\nPlease input the amount you will deposit:";
				      cin>>deposit;
				      balance=balance + deposit;
				      cout<<"\nThank you for updating your account!";
				      cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c10;
				      switch(c10)
				      {
					case 'Y':
					case 'y':
						goto mainmenu;

					case 'N':
					case 'n':
						cout<<"\nThank you for banking with us!";
						break;
					}


			}



		}



		break;

	 case 'N':
	 case 'n':
		cout<<"Thank you for banking with us!.";
		break;
	 default:
		cout<<"Your choice is invalid.";

	}




	getch();
	return 0;



}
}
There is a misplaced {} and i can't find it please help me
Well, you have two close-braces at the end of your main function, which doesn't look right.
All your braces has their counterpart, so there is no syntax errors. Why do you think that there is a braces problem?

If you cannot reason about your code structure, it is your fault. In this case you have function which is too long (functions should be no larger than 30 lines, maximut 50 if you have a very good reason) and goto usage.
@MiiNiPaa

I'm sorry i'm just new to programming.
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
#include<iostream.h>
#include<conio.h>
#include<string.h>
main(){
	clrscr();
	char  name[100],c1,c2,c3,c4,c5,c6,c7,c8,c9,c11,c10,c12,c13,c14,c15,c16;
	float balance,deposit,withdrawal;
	cout<<"Enter your name:";
	cin>>name;
	cout<<"\nHello "<<name<<"! Welcome to BPSU Online Banking System.";
	cout<<"\nThank you for creating an account with us. To better serve you, please provide us the following information.";
loop:
	cout<<"\n\nAccount Type:";
	cout<<"\n[S]avings";
	cout<<"\n[C]hecking";
	cout<<"\nEnter your choice:";
	cin>>c1;
	switch(c1)
	{
	 case 'S':
	 case 's':
		cout<<"Thank you for choosing a savings account.";
		break;

	 case 'C':
	 case 'c':
		cout<<"Thank you for choosing a checking account.";
		break;
	 default:
		cout<<"Your choice is invalid.";
		goto loop;
	}
	 if(c1 == 'c' && 'C')
	{
icloop:		cout<<"\nPlease input your initial balance:";
		cin>>balance;
		if(balance>=10000)
		{
			cout<<"\nThank you for opening an account with us!";
			cout<<"\nWould you like to have another transaction?[y/n]";
		}
		else
		{
		cout<<"\nYou have entered a balance that is below the minimum initial balance for a checking account. Please input an amount greater than or equal to 10000!";
			goto icloop;
		}
	}



	if(c1 == 's' && 'S')
		{
     isloop:	cout<<"\nPlease input your initial balance:";
		cin>>balance;
		if(balance>=5000)
			{
			cout<<"\nThank you for opening an account with us!";

			cout<<"\nWould you like to have another transaction? [y/n]";

			}
			else
			{    cout<<"\nYou have entered a balance that is below the minimum initial balance for a savings account. Please input an amount greater than or equal to 5000!";
			goto loop;
			}
		}
	cin>>c2;
	switch (c2)
	{
	 case 'Y':
	 case 'y':
mainmenu:	clrscr();
		cout<<"BPSU Online Banking System Main Menu";
		cout<<"\n\n[B]alance Inquiry";
		cout<<"\n[D]eposit";
		cout<<"\n[W]ithdraw";
		cout<<"\n[E]xit";
		cout<<"\nEnter your choice:";
		cin>>c3;
		switch(c3)
		{
		  case 'B':
		  case 'b':
			clrscr();
			cout<<"Balance Inquiry";
			if(c3 == 'c' && 'C')
			{
			cout<<"\n\nAccount Type:Checking Account";
			}
			else if(c3 == 'S' && 's')
			{
			cout<<"\n\nAccount Type:Savings Account";
			}
			else
			cout<<"\nCurrent Balance:"<<balance<<"";
transact:   cout<<"\nWould you like to do another transaction? [y/n]";
			cin>>c4;
			switch(c4)
			{
				case 'Y':
				case 'y':
					goto mainmenu;

				case 'N':
				case 'n':
					cout<<"\nThank you for banking with us!";
					break;
				
				default:
					cout<<"\nYour choice is invalid!";
					goto transact;
			}


		  case 'D':
		  case 'd':
deposit:	clrscr();
			cout<<"Deposit an Amount";
			cout<<"\n\nPlease choose how much you want to deposit:";
			cout<<"\n[5]00";
			cout<<"\n[1]000";
			cout<<"\n[2]000";
			cout<<"\n[50]00";
			cout<<"\n[O]ther:";
			cin>>c5;
			switch(c5)
			{
				case '5':
				      balance =balance + 500;
				      cout<<"\nThank you for updating your account!";
trans1:				  cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c6;
				      switch(c6)
						{
						case 'Y':
						case 'y':
							goto mainmenu;


						case 'N':
						case 'n':
							cout<<"\nThank you for banking with us!";
							break;
						default:
							cout<<"\nYour choice is invalid!";
							goto trans1;
						}
				case '1':
				      balance =balance + 1000;
				      cout<<"\nThank you for updating your account!";
trans2:				  cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c7;
				      switch(c7)
						{
						case 'Y':
						case 'y':
							goto mainmenu;

						case 'N':
						case 'n':
							cout<<"\nThank you for banking with us!";
							break;
						default:
							cout<<"\nYour choice is invalid!";
							goto trans2;
						}
				case '2':
				      cout<<"\nThank you for updating your account!";
				      balance =balance + 2000;
trans3:				  cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c8;
				      switch(c8)
						{
						case 'Y':
						case 'y':
							goto mainmenu;

						case 'N':
						case 'n':
							cout<<"\nThank you for banking with us!";
							break;
						default:
							cout<<"\nYour choice is invalid!";
							goto trans3;
						}
				case '50':
				      cout<<"\nThank you for updating your account!";
					  balance =balance + 5000;
trans4:				  cout<<"\nWould you like to do another transaction? [y/n]";
					  cin>>c9;
				      switch(c9)
						{
						case 'Y':
						case 'y':
							goto mainmenu;

						case 'N':
						case 'n':
							cout<<"\nThank you for banking with us!";
							break;
						default:
							goto trans4;
						}
				case 'o':
				case 'O':
				      cout<<"\n\nPlease input the amount you will deposit:";
				      cin>>deposit;
				      balance=balance + deposit;
				      cout<<"\nThank you for updating your account!";
trans5:				  cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c10;
				      switch(c10)
						{
							case 'Y':
							case 'y':
								goto mainmenu;

							case 'N':
							case 'n':
								cout<<"\nThank you for banking with us!";
								break;
							default:
								goto trans5;
						}

			default:
					cout<<"\nYour input is invalid!";
					goto deposit;
			}

		 case 'W':
		 case 'w':
wdraw:		clrscr();
			cout<<"Withdraw an Amount";
			cout<<"\n\nPlease choose how much you want to withdraw:";
			cout<<"\n[5]00";
			cout<<"\n[1]000";
			cout<<"\n[2]000";
			cout<<"\n[50]00";
			cout<<"\n[O]ther:";
			cin>>c11;
			switch(c11)
			{
				case '5':
				      balance =balance - 500;
				      cout<<"\nThank you for updating your account!";
				      cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c6;
				      switch(c6)
						{
						case 'Y':
						case 'y':
							goto mainmenu;


						case 'N':
						case 'n':
							cout<<"\nThank you for banking with us!";
							break;
						}
				case '1':
				      balance =balance - 1000;
				      cout<<"\nThank you for updating your account!";
				      cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c7;
				      switch(c7)
						{
						case 'Y':
						case 'y':
							goto mainmenu;

						case 'N':
						case 'n':
							cout<<"\nThank you for banking with us!";
							break;
						}
				case '2':
				      cout<<"\nThank you for updating your account!";
				      balance =balance - 2000;
				      cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c8;
				      switch(c8)
						{
						case 'Y':
						case 'y':
							goto mainmenu;

						case 'N':
						case 'n':
							cout<<"\nThank you for banking with us!";
							break;
						}
				case '50':
				      cout<<"\nThank you for updating your account!";
					  balance =balance - 5000;
					  cout<<"\nWould you like to do another transaction? [y/n]";
					  cin>>c12;
						switch(c12)
						{
						case 'Y':
						case 'y':
							goto mainmenu;

						case 'N':
						case 'n':
							cout<<"\nThank you for banking with us!";
							break;
						}
				case 'o':
				case 'O':
withloop:			  cout<<"\n\nPlease input the amount you will withdraw:";
				      cin>>withdrawal;
				      if(withdrawal > balance)
						{
						cout<<"\nThe amount that you would like to withdraw is greater than the current balance.";
						goto withloop;
						}
					  balance = balance - withdrawal;
				      cout<<"\nThank you for updating your account!";
				      cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c10;
				      switch(c10)
						{
							case 'Y':
							case 'y':
								goto mainmenu;

							case 'N':
							case 'n':
								cout<<"\nThank you for banking with us!";
								break;
						}

			
			
			
			}
				
				
				
		case 'e':
		case 'E':
				cout<<"\nHave a nice day!";
				break;
		default:
				cout<<"\nYour choice is invalid!";
				goto mainmenu;
		}


		






		
		
	 case 'N':
	 case 'n':
		cout<<"Thank you for banking with us!.";
		break;
	 default:
		cout<<"Your choice is invalid.";
	}

	getch();
	return 0;
}	 
The above code is my latest code, i found some wrong stuffs like when i press n after checking the balance inquiry, it goes to deposit menu.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
cout<<"\nWould you like to do another transaction? [y/n]";
			cin>>c4;
			switch(c4)
			{
				case 'Y':
				case 'y':
					goto mainmenu;

				case 'N':
				case 'n':
					cout<<"\nThank you for banking with us!";
					break;
				
				default:
					cout<<"\nYour choice is invalid!";
					goto transact;
			}
Hi,

Here is your mission:

1. Get rid of all goto's, repetitive code and other nightmares :+) Learn how to loop, and have functions instead. See my reply to your other topic.

2. Always initialise variables with some thing, preferably on the same line as declaration. char MyChar = 'z';

3. Understand why double posting is not cool. goto 1

4. See my reply to your other topic. goto 3

5. Understand why double posting is not cool. goto 7

6. See my reply to your other topic. goto 3

7. Write pseudo code to organise your ideas. goto 1

Good luck, and look forward to your new code :+) Regards
@TheIdeasMan

I'm really confused right now, because i don't know how do i make functions to shorten my program. Please enlighten me.
Ok,

Have a look a t the tutorial on the the upper left of this page. There is also reference material there.

Hope all goes well
bro can you please tell me what lines should i convert into 1 function, i'll post the code
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
#include<iostream.h>
#include<conio.h>
#include<string.h>
main(){
	clrscr();
	char  name[100],c1,c2,c3,c4,c5,c6,c7,c8,c9,c11,c10,c12,c13,c14,c15,c16;
	float balance,deposit,withdrawal;
	cout<<"Enter your name:";
	cin>>name;
	cout<<"\nHello "<<name<<"! Welcome to BPSU Online Banking System.";
	cout<<"\nThank you for creating an account with us. To better serve you, please provide us the following information.";
loop:
	cout<<"\n\nAccount Type:";
	cout<<"\n[S]avings";
	cout<<"\n[C]hecking";
	cout<<"\nEnter your choice:";
	cin>>c1;
	switch(c1)
	{
	 case 'S':
	 case 's':
		cout<<"Thank you for choosing a savings account.";
		break;

	 case 'C':
	 case 'c':
		cout<<"Thank you for choosing a checking account.";
		break;
	 default:
		cout<<"Your choice is invalid.";
		goto loop;
	}
	 if(c1 == 'c' && 'C')
	{
icloop:		cout<<"\nPlease input your initial balance:";
		cin>>balance;
		if(balance>=10000)
		{
			cout<<"\nThank you for opening an account with us!";
			cout<<"\nWould you like to have another transaction?[y/n]";
		}
		else
		{
		cout<<"\nYou have entered a balance that is below the minimum initial balance for a checking account. Please input an amount greater than or equal to 10000!";
			goto icloop;
		}
	}



	if(c1 == 's' && 'S')
		{
     isloop:	cout<<"\nPlease input your initial balance:";
		cin>>balance;
		if(balance>=5000)
			{
			cout<<"\nThank you for opening an account with us!";

			cout<<"\nWould you like to have another transaction? [y/n]";

			}
			else
			{    cout<<"\nYou have entered a balance that is below the minimum initial balance for a savings account. Please input an amount greater than or equal to 5000!";
			goto loop;
			}
		}
	cin>>c2;
	switch (c2)
	{
	 case 'Y':
	 case 'y':
mainmenu:	clrscr();
		cout<<"BPSU Online Banking System Main Menu";
		cout<<"\n\n[B]alance Inquiry";
		cout<<"\n[D]eposit";
		cout<<"\n[W]ithdraw";
		cout<<"\n[E]xit";
		cout<<"\nEnter your choice:";
		cin>>c3;
		switch(c3)
		{
		  case 'B':
		  case 'b':
			clrscr();
			cout<<"Balance Inquiry";
			if(c3 == 'c' && 'C')
			{
			cout<<"\n\nAccount Type:Checking Account";
			}
			else if(c3 == 'S' && 's')
			{
			cout<<"\n\nAccount Type:Savings Account";
			}
			else
			cout<<"\nCurrent Balance:"<<balance<<"";
transact:   cout<<"\nWould you like to do another transaction? [y/n]";
			cin>>c4;
			switch(c4)
			{
				case 'Y':
				case 'y':
					goto mainmenu;

				case 'N':
				case 'n':
					cout<<"\nThank you for banking with us!";
					break;
				
				default:
					cout<<"\nYour choice is invalid!";
					goto transact;
			}


		  case 'D':
		  case 'd':
deposit:	clrscr();
			cout<<"Deposit an Amount";
			cout<<"\n\nPlease choose how much you want to deposit:";
			cout<<"\n[5]00";
			cout<<"\n[1]000";
			cout<<"\n[2]000";
			cout<<"\n[50]00";
			cout<<"\n[O]ther:";
			cin>>c5;
			switch(c5)
			{
				case '5':
				      balance =balance + 500;
				      cout<<"\nThank you for updating your account!";
trans1:				  cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c6;
				      switch(c6)
						{
						case 'Y':
						case 'y':
							goto mainmenu;


						case 'N':
						case 'n':
							cout<<"\nThank you for banking with us!";
							break;
						default:
							cout<<"\nYour choice is invalid!";
							goto trans1;
						}
				case '1':
				      balance =balance + 1000;
				      cout<<"\nThank you for updating your account!";
trans2:				  cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c7;
				      switch(c7)
						{
						case 'Y':
						case 'y':
							goto mainmenu;

						case 'N':
						case 'n':
							cout<<"\nThank you for banking with us!";
							break;
						default:
							cout<<"\nYour choice is invalid!";
							goto trans2;
						}
				case '2':
				      cout<<"\nThank you for updating your account!";
				      balance =balance + 2000;
trans3:				  cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c8;
				      switch(c8)
						{
						case 'Y':
						case 'y':
							goto mainmenu;

						case 'N':
						case 'n':
							cout<<"\nThank you for banking with us!";
							break;
						default:
							cout<<"\nYour choice is invalid!";
							goto trans3;
						}
				case '50':
				      cout<<"\nThank you for updating your account!";
					  balance =balance + 5000;
trans4:				  cout<<"\nWould you like to do another transaction? [y/n]";
					  cin>>c9;
				      switch(c9)
						{
						case 'Y':
						case 'y':
							goto mainmenu;

						case 'N':
						case 'n':
							cout<<"\nThank you for banking with us!";
							break;
						default:
							goto trans4;
						}
				case 'o':
				case 'O':
				      cout<<"\n\nPlease input the amount you will deposit:";
				      cin>>deposit;
				      balance=balance + deposit;
				      cout<<"\nThank you for updating your account!";
trans5:				  cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c10;
				      switch(c10)
						{
							case 'Y':
							case 'y':
								goto mainmenu;

							case 'N':
							case 'n':
								cout<<"\nThank you for banking with us!";
								break;
							default:
								goto trans5;
						}

			default:
					cout<<"\nYour input is invalid!";
					goto deposit;
			}

		 case 'W':
		 case 'w':
wdraw:		clrscr();
			cout<<"Withdraw an Amount";
			cout<<"\n\nPlease choose how much you want to withdraw:";
			cout<<"\n[5]00";
			cout<<"\n[1]000";
			cout<<"\n[2]000";
			cout<<"\n[50]00";
			cout<<"\n[O]ther:";
			cin>>c11;
			switch(c11)
			{
				case '5':
				      balance =balance - 500;
				      cout<<"\nThank you for updating your account!";
				      cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c6;
				      switch(c6)
						{
						case 'Y':
						case 'y':
							goto mainmenu;


						case 'N':
						case 'n':
							cout<<"\nThank you for banking with us!";
							break;
						}
				case '1':
				      balance =balance - 1000;
				      cout<<"\nThank you for updating your account!";
				      cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c7;
				      switch(c7)
						{
						case 'Y':
						case 'y':
							goto mainmenu;

						case 'N':
						case 'n':
							cout<<"\nThank you for banking with us!";
							break;
						}
				case '2':
				      cout<<"\nThank you for updating your account!";
				      balance =balance - 2000;
				      cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c8;
				      switch(c8)
						{
						case 'Y':
						case 'y':
							goto mainmenu;

						case 'N':
						case 'n':
							cout<<"\nThank you for banking with us!";
							break;
						}
				case '50':
				      cout<<"\nThank you for updating your account!";
					  balance =balance - 5000;
					  cout<<"\nWould you like to do another transaction? [y/n]";
					  cin>>c12;
						switch(c12)
						{
						case 'Y':
						case 'y':
							goto mainmenu;

						case 'N':
						case 'n':
							cout<<"\nThank you for banking with us!";
							break;
						}
				case 'o':
				case 'O':
withloop:			  cout<<"\n\nPlease input the amount you will withdraw:";
				      cin>>withdrawal;
				      if(withdrawal > balance)
						{
						cout<<"\nThe amount that you would like to withdraw is greater than the current balance.";
						goto withloop;
						}
					  balance = balance - withdrawal;
				      cout<<"\nThank you for updating your account!";
				      cout<<"\nWould you like to do another transaction? [y/n]";
				      cin>>c10;
				      switch(c10)
						{
							case 'Y':
							case 'y':
								goto mainmenu;

							case 'N':
							case 'n':
								cout<<"\nThank you for banking with us!";
								break;
						}

			
			
			
			}
				
				
				
		case 'e':
		case 'E':
				cout<<"\nHave a nice day!";
				break;
		default:
				cout<<"\nYour choice is invalid!";
				goto mainmenu;
		}


		






		
		
	 case 'N':
	 case 'n':
		cout<<"Thank you for banking with us!.";
		break;
	 default:
		cout<<"Your choice is invalid.";
	}

	getch();
	return 0;
}	 
Hi,

Code that is a candidate for being inside a function:

Any code that might otherwise be repeated - we want to avoid that :+)

Anything in a compound statement. A compound statement is code between braces. So this might include anything inside a while or for loop. Ideally each case in a switch could call a function. Also, code in the body of an if or else if , or else statement.

This is an example of one general simple way to organise a program:

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
#include <iostream>

// other includes of STL headers

// other includes of your own headers

//function declarations
void GetInput(); // arguments up to you
void ValidateInput(); // arguments up to you
/*ReturnType*/ ProcessInput(); // arguments up to you
/*ReturnType*/ PrintOutput(); // arguments up to you

int main() {

// Reading the code in main tells an overview of what is happening
// Detail is in the function definitions

// must call the functions, otherwise nothing happens

  GetInput(); // arguments up to you, must match the declaration above

  ValidateInput(); // arguments up to you, must match the declaration above

  ProcessInput(); // arguments up to you, must match the declaration above

  PrintOutput(); // arguments up to you, must match the declaration above


}  // end of main

//function definitions

void GetInput() { // arguments up to you, must match the declaration above

}

void ValidateInput() { // arguments up to you, must match the declaration above

}

/*ReturnType*/ ProcessInput() { // arguments up to you, must match the declaration above
  // a function can call another function
  // use this idea to break functions into smaller ideas
}

/*ReturnType*/ PrintOutput() { // arguments up to you, must match the declaration above

}


Other good things to do:

Write pseudo code. Start out with with general ideas, write them as comments. Go back, break down the problem into smaller ideas, and refine each item by putting more detail. Keep doing this until you are happy to convert the comments into code. Doing this helps identify what should be in loops, switches and functions.

Have meaningful variable names. Don't abbreviate too much, if at all. Write Withdraw rather than wdraw If the names of functions and variables are good, the code should be self documenting and tell a story of what is happening. Even if someone doesn't know the technical detail of what you are doing, they should still have a good idea of what is happening. Put comments to any web pages like wiki or other documentation if that is helpful.

Write your own documentation as comments, about what a function does.

Keep the scope of your variables as local as possible. Send variables to functions as arguments, don't have global's.

Make variables const wherever possible. Arguments / parameters are often const , because we shouldn't be able to change them inside the function.

Pass a variable by using a reference in the function parameter, to change the value of that variable in the outer scope. Does Turbo C++ 3.0 have references? - maybe not, well pointers then instead. Edit : That might be more advanced

Write comments to say what the expected range of values for variables are - e.g. must be positive and less than 100 say. Edit :This might give some clues about the type to use- consider unsigned int instead of int

Write comments to say what the expected value of function arguments should be, for the function to work properly. This is called pre-conditions. Put this in as part of the function documentation, described above.

Write comments to say what the expected value of function return values should be, for the function to provide a valid answer. This is called post-conditions.


Some things not to do:

Global variables;
Goto;

Don't make functions too big - try for a limit of 40 lines say - or even less. This includes main()

I converted some of your code into some function definitions:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20



void ShowMainMenu () {

	cout << "\nThank you for creating an account with us. To better serve you, please provide" 
        cout << " us the following information.";

	cout << "\n\nAccount Type:";
	cout << "\n [S]avings";
	cout << "\n [C]hecking";
        cout << "\n [Q]uit";

}

void  GetUserMenuSelection(char& MenuSelection) {

	cout << "\nEnter your choice:";
        cin>> MenuSelection;
}


Hope this helps you out.
Last edited on
Thank you bro!, just 1 thing why does it says declaration syntax error?
Thank you bro!, just 1 thing why does it says declaration syntax error?


Where? What?

Please provide more information, post your compiler output, maybe a snippet of the offending code (not the whole thing again)
@TheIdeasMan

bro, i'm afraid I won't be able to convert the statements to function because

1. I can't really understand the function.
2. I need to still fix the output errors.
3. The deadline for this program is until monday.

so i think i'll just clean this code first then study functions afterwards.

Thank you very much for your help bro. I really appreciate it.
Hi,

So were or did you make any sense from this very easy tutorial ?

http://www.cplusplus.com/doc/tutorial/functions/


As I mentioned earlier, there is a whole tutorial there.
@TheIdeasMan

Pleas bro guide me, i need it badly.
What did you make of the link I gave you?
Topic archived. No new replies allowed.