Payoff table for a loan?

I need to develop a c++ program that will provide the payoff table for a revolving credit card. The user should be prompted for the amount of the loan, annual interest rate, and amount to be paid each month. The output should be a formatted list showing the month number, amount paid on the principal, amount paid on the interest, and the remaining amount of the loan.

The calculations should be done within a while loop that will run as long as the balance is greater than zero. This is the part that's giving me trouble. I just don't know what to put inside the loop or how to make it repeat.

Given calculations:
interest = balance * (rate/12)
principal = payment - interest
new balance = balance - principal

This is what 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
// include statements
#include <iostream>
#include <iomanip>
using namespace std;

// start of main
int main(void) 
{
// Declare variables
int month = 0;
double interest = 0.0;
double principal = 0.0;
double balance = 0.0;
double rate = 0.0;
double perMonth = 0.0;
double newBalance = 0.0;

// Inputs
cout << "Loan amount: $";
cin >> principal;

cout << "Annual interest rate: ";
cin >> rate;

cout << "Amount to be paid each month: $";
cin >> perMonth;
cout << endl;

// Calculations
balance = principal;

interest = balance * ((rate/100)/12);

principal = perMonth - interest;

newBalance = balance - interest;

rate = (12 * interest) / newBalance;


// loop
while (newBalance > 0) {

cout << "Loan amount: $";
cin >> principal;
cout << "Annual interest rate: ";
cin >> rate;
cout << "Amount to be paid each month: $";
cin >> perMonth;
cout << endl;

cout << "Month" << " Principal" << " Interest" << " Balance" << endl;
cout << month++ << principal << rate << newBalance << endl;
}


system("pause");
return 0;
Your cin stuff (lines 45, 47, 49) don't change every iteration do they? Since these should only be set once, you should delete those lines.

On the other hand, you're supposed to calculate the balance, interest and new balance every month and then display those. Stick those inside the loop.


Also, why are you recalculating principal? Does that really need to change?
I removed the cin lines, and included the calculations within the loop but now I seem to be stuck in an infinite loop. The only value that changes is month, everything else only calculates once.

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
// start of main
int main(void) 
{
	// Declare variables
	int month = 0;
	double interest = 0.0;
	double principal = 0.0;
	double balance = 0.0;
	double rate = 0.0;
	double perMonth = 0.0;
	double newBalance = 0.0;

	// Inputs
	cout << "Loan amount: $";
	cin >> principal;

	cout << "Annual interest rate: ";
	cin >> rate;

	cout << "Amount to be paid each month: $";
	cin >> perMonth;
	cout << endl;

	// calculations
	balance = principal;
	interest = balance * ((rate/100)/12);
	principal = perMonth - interest;
	newBalance = balance - interest;
	rate = (12 * interest) / newBalance;

	// loop
	while (newBalance > 0) {

	// Calculations
	balance = principal;
	interest = balance * ((rate/100)/12);
	newBalance = balance - interest;
		
	cout << "Month" << "  Principal" << "  Interest" << "  Balance" << endl;
	cout << month++ << principal << rate << newBalance << endl;
	}


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