Simple ATM Program

Hi guys, i'm back again. This is the 4th and last machine problem for me to do. I need to create a simple ATM program, starting from creating an account, displaying the balance, depositing and withdrawing an amount.Uppercase and lowercase letters must be allowed. I am now here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream.h>
#include<conio.h>
#include<string.h>
main(){
	clrscr();
	char  name,choice;
	float balance;
	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.";
	cout<<"\n\nAccount Type:";
	cout<<"\n[S]avings";
	cout<<"\n[C]hecking
	cout<<"\nEnter your choice:";
	cin>>choice;

	getch();
	return 0;




} 
Last edited on
this is my updated code with the switch statement
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
#include<iostream.h>
#include<conio.h>
#include<string.h>
main(){
	clrscr();
	char  name[100],choice;
	float balance;
	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.";
	cout<<"\n\nAccount Type:";
	cout<<"\n[S]avings";
	cout<<"\n[C]hecking";
	cout<<"\nEnter your choice:";
	cin>>choice;
	switch (choice)
	{
	 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.";
		choice =0;
	 }
	 return choice;

	getch();
	return 0;




}


Everytime i put s or S or c or C the program exits. Why is that?
Immediately after your switch statement, you have a return statement. When you return from main, you exit the program.
Hi,

I gather (rather am guessing) you are using Turbo C++ 3.0 ? (no std namespace, it accepts main without int)

Does it display the text in lines 21 or 26?

The break on lines 22 and 27 cause the switch to end, which then does line 32.

Line 32 returns from main().

If you do some more code, so that each case calls a function to do that task, then you might see some better results :+)

Good Luck
@MikeyBoy thanks bro,

@TheIdeasMan yep i'm using a turbo c++ 3.0, my teacher told us to use this. thanks bro
here is my updated 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
#include<iostream.h>
#include<conio.h>
#include<string.h>
main(){
	clrscr();
	char  name[100],choice;
	float balance;
	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>>choice;
	switch (choice)
	{
	 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;
	 }


	getch();
	return 0;




}
Help me guys, everytime it asks me to input the initial balance, it closes.

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
#include<iostream.h>
#include<conio.h>
#include<string.h>
main(){
	clrscr();
	char  name[100],choice;
	float isbalance,icbalance;
	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>>choice;
	switch (choice)
	{
	 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(choice == 'c' && 'C')
		{
		cout<<"Please input your initial balance:";
		cin>>icbalance;
		if(icbalance>=10000)
		{
			cout<<"\nThank you for opening an account with us!";
			cout<<"\nWould you like to have another transaction?";
			break;


		}
		}
	    }



	cout<<"Please input your initial balance:";
	cin>>

	getch();
	return 0;




}
well i made some edits and i got this

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
#include<iostream.h>
#include<conio.h>
#include<string.h>
main(){
	clrscr();
	char  name[100],choice;
	float isbalance,icbalance;
	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>>choice;
	switch (choice)
	{
	 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(choice == 'c' && 'C')
		{
		cout<<"\nPlease input your initial balance:";
		cin>>icbalance;
		if(icbalance>=10000)
		{
			cout<<"\nThank you for opening an account with us!";
			cout<<"\nWould you like to have another transaction?";
		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!";
		}
		}



	getch();
	return 0;




}

Hi,

Ok, line 33 is wrong, but I reckon you should avoid doing that anyway.

Instead put the code in lines 35 to 46 in it's own function, and call that function from the case in line 27.

Also, avoid having goto . Instead, provide an Another Account option, which essentially does nothing apart from allowing the while to loop again. Also provide quit option for the switch. This case should set a Quit bool variable to true. Then put the whole switch into a while loop:

1
2
3
4
5
6
7

bool Quit = false;
while (!Quit) {

   // your switch

}


As a matter of style, the braces should line up in the same column as the statement it is associated with. So on lines 39 and 46, these braces should be in the same column as the i (if) on line 34.

Btw, if you want to test if more than one thing is true, then it looks like this:

1
2
3
4
5
6
7
char A = 'Q' ;
char B = 'q' ; 

if (A == 'Q'  && B == 'q')  //true 
{

}


Good Luck !!
Hi bro,

i created the other thread (http://www.cplusplus.com/forum/general/174998/) please take a look at it and if possible tell me how to shorten it, and it has the latest code. i'll close this thread now
Topic archived. No new replies allowed.