ATM program needs help here!!!

#include <iostream>
#include <string>
using namespace std;

void checkbal(string accnum, double balance);
void withdraw(string accnum, double balance);
void deposit(string accnum,double balance);
void option(string accnum, int balance);

void main(){

int pin, accnum, pintrials;

pin=12345;
pintrials=3;

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');
Last edited on
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?

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
int main(){

    int pin, accnum, pintrials;
    
    pin=12345;
    pintrials=3;
    
    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);
    
//call functions here?

    system("pause");
}
How to call function in this program?
Can you teach me how to solve it?
I have try to type in option(accnum,balance); at the place you said, but its cannot go through the withdraw and deposit.
How to fixed it?
Topic archived. No new replies allowed.