Write a program that calculates the closing balance for an indeterminate number of checkbooks. The program must logically flow as follows:
* Step 1. Ask for the data for the first checkbook- opening balance, withdrawals and deposits
* Step 2. Display the opening balance, the number of withdrawals, the number of deposits and the closing balance
* Step 3. Ask whether the user wishes to calculate the balance on another checkbook:
o If so, go back to Step 1
o Otherwise, end the program
All data will be obtained from standard input. The format for the monetary data will be a series of numbers, each one occurring on its own line of input. The first number is the opening balance. Thereafter, the user will enter withdrawals as negative numbers and deposits as positive numbers. The user will signify the end of the monetary data by entering a zero. The user will enter a lower case 'y' to select the option of balancing another checkbook; otherwise, the user will enter a lower case 'n'.
This is my code so far:
#include <iostream>
using namespace std;
// Ask the user to input the balace.
int askUser(int balance)
{
cout << "Please enter the current balance in checkbook: " << endl;
cin >> balance;
return balance;
}
// Calculate the number of deposits and withdrawals.
int addMoney(int withdrawals, int deposits, int total)
{
cout << "Enter a negative integer to indicate a withdrawal.\n";
int money;
do
{
cout << "Please deposit or withdraw money into the account: 0 ends the transaction " << endl;
cin >> money;
total += money;
if (money > 0 ) ++deposits;
else if (money < 0) ++withdrawals;
}
while (money != 0);
return 0;
}
// Calcuate the total balance after the user withdraws and deposits money and provide a choice to balance another checkbook.
void OutputData(int balance, int withdrawals, int deposits, int total, char decision)
{
cout << "Opening balance: " << balance << endl;
cout << "Number of Deposits: " << deposits << endl;
cout << "Number of Withdrawls: " << withdrawals << endl;
balance += total;
cout << "Closing Balance: " << balance << endl;
cout << "To balance another checkbook press y, otherwise press n to quit the program: " << endl;
cin >> decision;
}
//Call the above functions and determining wherether to end the loop or continue with the calculations.
int main()
{
char decision = 0;
int balance, withdrawals, deposits, total, money;
money = 0;
balance = 0;
deposits = 0;
withdrawals = 0;
total = 0;
balance = 0;
int finish = 1;
do // Using the do-while loop to call the fucntions.
{
askUser(balance);
addMoney(withdrawals, deposits, total);
OutputData(balance, withdrawals, deposits, total, decision);
}
while (decision == 'y');
}
I am having trouble with this because I am not suppose to use reference variables. Can anyone please tell me what I am doing wrong? Everytime I try to return a value, the calculations always come out to be zero. I don't know why this is happening. Please help!!!