1 2 3 4 5 6 7 8 9 10 11
|
void Withdraw()
{
cout <<"\tEnter the amout to withdraw : ";
cin >> d;
while(d > balance || d<=0 || balance - d < 500){
cout <<"\t Please enter again.\n\n";
cin>>d;
}
balance = balance - d;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
|
This works, but that (maybe) is the function you want :
1 2 3 4 5 6 7 8 9 10 11
|
int Withdraw(int bal)
{
cout <<"\tEnter the amout to withdraw : ";
cin >> d;
while(d > bal || d<=0 || bal - d < 500){
cout <<"\t Please enter again.\n\n";
cin>>d;
}
return (bal - d); bal = bal - d; return bal;
}
|
This function I added the parameter
"int bal". This means before calling this function you must give the function all necessary parameters (In this case the function
Withdraw() requires an "int" parameter (bal)). Now, please look at the simple example :
1 2 3 4
|
int Average(int a, int b)
{
return (a + b) / 2;
}
|
int c = Average(10, 24);
You can see this function has a "int" returning value. The parameters are "a", "b", and the code is just a final value of the expression "(a + b) / 2"
And the code : "c = Average(10, 24);" I input in order a = 10, b = 24
So, making a function is very easy. Remember before making any function :
1- Name
2- Parameter list (Optional)
3- Returning value (Optional) - Consider about the target carefully
4- Code inside
And the function I mentioned above :
Name : Withdraw
Parameter list : int (bal)
Returning value : bal (the remaining balance)
Code : Input, withdraw....
Target : Get the remaining balance
And the use of this function :
1 2 3
|
case WITHDRAW :
balance = Withdraw(balance);
break;
|
(See cPlusPlus documentation & tutorials for more details)
And, the similar function :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
int Deposit(int bal)
{ d = 0;
cout <<"\tEnter the amount to deposit (min 500) : ";
cin >> d;
while(d < 500)
{
cout <<"\tYou enter is below the minimum deposit. Please enter again.\n\n";
cin >> d;
}
bal = bal + d;
return bal;
}
|
Do you know the hand-checking skill?