Anyone help me???

#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 sel,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>>sel;
do{
switch(withdraw){
case 1:wdamount=100; //<-----Why I cannot choose any of this?
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;
default:cout<<"Invalid Input."<<endl;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');
}


I cannot choose the withdraw amount in switch loop, anyone teach me how to solve?
Last edited on
Put your code in the source code.
Code tags make it much easier to read your code. I am not going to try to fix the formatting, but...
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
void withdraw(string accnum, int balance){
int withdraw=0,wdamount=0;    // withdraw = 0
char sel,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>>sel;    // Is this supposed to be cin >> withdraw;?
do{
switch(withdraw){    // withdraw = 0 still
case 1:wdamount=100; //<-----Why I cannot choose any of this?
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;
default:cout<<"Invalid Input."<<endl;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;
}
Topic archived. No new replies allowed.