12 month interest summary

I am trying to print out a report for a 12 month interest summary. So far, I cannot seem to get the ending balance for the previous month to be the starting balance for the next month. I can't seem to get the loop to work. It should read:

Starting Bal Interest Ending Balance
4000 16.00 4016
4016 16.06 4032.06
...

Here is the code I have so far:

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

#include "SavingsAccount.h"

int main()
{
	//Create one instance of a SavingsAccount
	SavingsAccount myAccount("Z1234A", 4000.0, 0.004);
	double currentBalance;
	char makeDeposit = ' ';
	double amount = 0.0;
	char makeWithdrawal = ' ';
	double INT_RATE = .004;
	double endingBal = 0.0;

	//Set decimal spaces to 2
	cout << fixed << setprecision(2);

	string accountNumber;
	accountNumber = myAccount.getAcctNo();

	//Display the name of software and company
	cout << setw(55) << " BANKING SOLUTIONS SOFTWARE 1.0 " << endl;
	cout << setw(54) << "Prioleau Banking Corporation " << endl << endl;

	//Welcome the customer
	cout << setw(61) << "Welcome to the Prioleau Banking Corporation!" << endl << endl;

	//Display the current state of the account including
	//account number, current balance and interest rate	
	accountNumber = myAccount.getAcctNo();
	cout << "Your account number is: " << accountNumber << endl;

	currentBalance = myAccount.getBalance();
	cout << "Your current balance is: $" << currentBalance << endl;
	
	double startingRate;
	startingRate = myAccount.getInterestRate();
	cout << "The current interest rate is: " << ".4%" << endl << endl;
				
	//Customer makes a deposit
	cout << "Will you be making a deposit today (Y or N)?" << endl;
	cin >> makeDeposit;
	cout << endl;

	if (toupper(makeDeposit) == 'Y')
	{
		cout << "Please enter the amount that you would like to deposit." << endl;
		cin >> amount;
		cout << endl;
		
		myAccount.addToBalance(amount);
		currentBalance = myAccount.getBalance();
		
		//Display the ending state of the account
		cout << "Your current balance is now: $" << currentBalance << endl << endl;
	}
	else
		cout << "Thank you." << endl << endl;
	
	//Customer makes a withdrawal
	cout << "Will you be making a withdrawal today (Y or N)?" << endl;
	cin >> makeWithdrawal;
	cout << endl;

	if (toupper(makeWithdrawal) == 'Y')
	{
		cout << "Please enter the amount that you would like to withdraw." << endl;
		cin >> amount;
		cout << endl;
		
		myAccount.withdrawFromBalance(amount);
		currentBalance = myAccount.getBalance();
		
		//Display the ending state of the account
		cout << "Your current balance is now: $" << currentBalance << endl << endl;
	}
	else
		cout << "Thank you." << endl << endl;

	//Display a 12-month summary of the account that shows the effect
	//of the current interest rate on the growth of the balance
	//assuming that the interest is applied as simple interest once per month
	cout << "As of today's balance, here is a 12-month summary of the account that "<<
		    "shows the effect of the current interest rate on the growth " << 
			"of the balance; assuming that the interest is applied as simple interest "<<
			"once per month." << endl << endl << endl;
	
	//Headers
	cout << "Month" << setw(20) << "Starting" << setw(20) << "Interest" << setw(20)
			 << "Ending" << endl;
	cout << "  #" << setw(21) << "Balance" << setw(19) << "Earned" << setw(23)
			 << "Balance" << endl;

	//line number variable for print out
	int lineNum = 1;
		
	//Formula for ending balance
	endingBal = currentBalance + (currentBalance * INT_RATE);

	//12 month interest report output line 1		
	cout << setw(3) << lineNum << setw(21) << currentBalance + INT_RATE << setw(18) << currentBalance * INT_RATE 
		<< setw(24) << endingBal;
		cout << endl;
	
	while (lineNum <= 11)
	{
		//Line number counter for 12 month interest report output
		lineNum += 1;
		
		//12 month of interest report output
		cout << setw(3) << lineNum << setw(21) << endingBal + INT_RATE << setw(18) << currentBalance * INT_RATE 
			<< setw(24) << endingBal;
			cout << endl;
		
	}
	//end while
	
	//Thank customer and exit program
	cout << endl << endl;
	cout << "Thank you for choosing Prioleau Banking Corporation. Have a wonderful day!" << endl;

	cout << endl << endl;
	system ("pause");
	return 0;
}
Last edited on
Topic archived. No new replies allowed.