Why my system cannot terminate itself?

#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, pintrials,balance=5000;
string accnum;

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);
option(accnum, balance);
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=0;
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;
cin>>withdraw;
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;
}
cout<<"Do you want to continue? [Y/y-Yes N/n-No]";
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 transaction:"<<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 code, when my pintrials = 0, my system cannot terminate but go through the option menu below.Someone help me?
You call option(...) regardless whether x is true or not. You need an if clause before you call option(...)

Oh and please use code tags: [code]Your code[/code]
Read this: http://www.cplusplus.com/articles/z13hAqkS/
Last edited on
Topic archived. No new replies allowed.