Mortgage calculator. Last steps. Please help due soon

I need my code to display Month but it seems my code is skipping month's and not displaying 1, 2 3. It's going 1 , 3 ,5 and so on. This is the code i have for it int month = 1; and later on the code i have month++ That's my first mistake and i'm not sure how to possibly fix it. My second mistake is my Interest Paid output. This is the code i have for it interestPaid = loanBalance*i; This is on the while loop, but i'm not sure why it's not displaying the correct amount. It should display for month 1 = 500.00 , Month 2 = 498.28 and Month 3 = 496.55 and so on... However my code display's something close to it, but not that. i is my monthly interest rate. My code for it seems to be fine. If i can fix this two things i'll be able to finish the project. This is my entire code, someone please help me finish it and tell me how i can fix it so that my month is displayed in 1, 2, 3, etc.... and not 1, 3, 5, etc... And why my interest is not displaying what my professor has on his output screen (i provided the first three months on top in bold) If i can fix those things i'll have the rest. Here's my entire code

#include <iostream>
#include <iomanip>


using namespace std;
int main ( )

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
{

	int month = 1;
	// Holds the user's amount of loan.

	double loanAmount;

	// Holds the user's interest rate.
	
	double i;

	// Holds the user's yearly Interest Rate.

	double interestRate;

	// Holds the user's interest paid every month.

	double interestPaid;
	
	// "n" means the months it will take the user to pay off the loan.

	double n;

	// Holds the variable for total months.

	double years;

	// Holds payment data.

	double monthlyPayment;

	// Holds the user Principle paid.

	double principlePaid;

	// Holds the user Loan balance.

	double loanBalance;

	// Asks the user to input how much money they took out.

	cout<<"Enter loan amount ->";
	cin>>loanAmount;

	// Asks the user to input their interest rate.

	cout<<"Enter interest rate -->";
	cin>>interestRate;
	i = (interestRate/1200);

	// Asks the user to input the number of years they are taking the loan for.

	cout<<"Enter number of years of the laon ->";
	cin>>years;
	n = years*12;
	
	// Equation that determines the user's monthly payment.

	monthlyPayment = loanAmount*(i/(1-pow(1+i,-n)));

	// Equation for interest paid every month.

	interestPaid = loanAmount*i;

	// Equation for Principle paid.

	principlePaid = monthlyPayment-interestPaid;

	// Equation for Loan Balance

	loanBalance = loanAmount-principlePaid;







	cout<<"Month"<<"\t"<<"Payment"<<"\t"<<"Interest Paid"<<"\t"<<"Principle Paid"<<"\t"<<"Loan Balance"<<endl;
	// Beginning of while coding.
	
	do
	{
	

	cout<<month++<<"\t"<<fixed<<setprecision(2)<<monthlyPayment            // Code used to display monthly Payment.
		<<"\t"<<fixed<<setprecision(2)<<interestPaid                       // Code used to display Interest Paid.
	    <<"\t"<<fixed<<setprecision(2)<<principlePaid                      // Code used to display Principle Paid.
		<<"\t"<<fixed<<setprecision(2)<<loanBalance;                       // Code used to display Loan Balance.


	loanBalance = loanBalance-principlePaid;

	interestPaid = loanBalance*i;

	principlePaid = monthlyPayment-interestPaid;
	}

	while (loanBalance>0);

	cin.get ( ); cin.get ( );
	return 0;
}
Last edited on
Topic archived. No new replies allowed.