Your professor is talking about passing values by reference or by value.
If you pass a parameter by reference to a function, it will change that value for the rest of the program.
If you pass by value, it will change that value only for the scope of that function.
To pass by reference you need to include the ampersand sign (&) in your prototype and function declaration.
So lines 49-52 are all global variables.
1 2 3 4
|
char choice;
double deposit, withdraw;
double balance = 5000.00;
double positive_amount;
|
It's as if you declared them before the main function. (Delete them)
I believe you need to pass the balance by reference to your choice_opt function.
So your prototype should be:
double choice_opt(char, double&);
Your function call should be:
choice_opt(choice,balance);
Your function definition should be:
double choice_opt(char choice, double& balance)
.
Also delete double deposit, withdraw from main() and only include it in your choice_opt function. Like so:
1 2 3
|
double choice_opt(char choice)
{
double withdraw,deposit;
|
That should help a lot.
You don't need to pass by reference to the print_balance function.
Just make sure the prototype is properly declared.
void print_balance(double);
And the call is properly declared.
void print_balance(balance);