cout<<"***WELCOME TO ATM MAYBANK!!***"<< endl;
cout<<"Please Enter Your Account Number: ";
cin>>accnum;
bool x;
do{
cout << "\nPlease Enter Your PIN Number: ";
cin >> pin;
if (pin==12345){
cout << "PIN correct!" << endl;
pintrials = -1;
x = true;
}
else{
pintrials--;
cout << "You have "<< pintrials<< " attempts remaining."<<endl;
x = false;
}
if (pintrials == 0){
cout<<"\nYou have exceed the PIN attempts."<<endl;
cout<<"Please contact us in any branch of our bank."<<endl;
cout<<"Thank you."<<endl;
break;
}
}while (x != true);
system("pause");
}
void checkbal(string accnum, int balance){
cout<<"Account number:"<<accnum<<endl;
cout<<"Your balance is RM"<<balance<<endl;
}
void withdraw(string accnum, int balance){
int withdraw=0,wdamount;
char ans;
cout<<"Please choose your transaction."<<endl;
cout<<"1.)RM100"<<endl;
cout<<"2.)RM300"<<endl;
cout<<"3.)RM500"<<endl;
cout<<"4.)Enter value."<<endl;
do{
switch(withdraw){
case 1:wdamount=100;
cout<<"Withdraw RM100."<<endl;break;
case 2:wdamount=300;
cout<<"Withdraw RM300."<<endl;break;
case 3:wdamount=500;
cout<<"Withdraw RM500."<<endl;break;
case 4:cout<<"Enter withdraw value:RM";
cin>>wdamount;break;
}
if(withdraw==1 || withdraw==2 || withdraw==3 || withdraw==4)
break;
else
cout<<"Do you want to continue? [Y/y-Yes N/n-No]"<<endl;
cin>>ans;
}while(ans=='Y' && ans=='y');
balance=balance-wdamount;
cout<<"Your balance is RM"<<balance<<endl;
}
void deposit(string accnum, int balance){
int deposit;
cout<<"Please enter your cash into space provided."<<endl;
cout<<"Please enter amount that you put in :";
cin>>deposit;
balance=balance+deposit;
cout<<"Your balance now is RM"<<balance<<endl;
}
void option(string accnum, int balance){
int choice;
char ans;
do{
cout<<"Please choose your :"<<endl;
cout<<"1.)Check Balance."<<endl;
cout<<"2.)Cash Withdraw."<<endl;
cout<<"3.)Cash Deposit."<<endl;
cin>>choice;
switch(choice){
case 1:checkbal(accnum, balance);break;
case 2:withdraw(accnum, balance);break;
case 3:deposit(accnum,balance);break;
default:cout<<"Invalid Input."<<endl;
}
cout<<"Do you want to continue? [Y/y-Yes N/n-No]";
cin>>ans;
}while(ans=='Y'&&ans=='y');
}
This is my program, but it cant loop well when I compile it.
When I entered correct password, then the system will terminate.
Someone please help me, Thank you very much!
Your main function just validates the PIN entered - do you mean to call the other functions you've written?
You'll need to change where you have this check - && means both conditions are true and ans can't be both Y and y at the same time. }while(ans=='Y' && ans=='y');
Means I need to do what changes inside this loop?
I have try to change }while(ans=='Y' && ans=='y'); to }while(ans=='Y' || ans=='y');
Its still cannot go through the menu and stuck at the PIN there.
If you enter the correct password, the program as you have it will end because there are no further instructions to execute. I figure you mean to show them a menu once they enter the correct password?