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.
#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;
}
#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?
#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;
}
#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;
}
#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;
}
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
{
}
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