Monthly Payment Calc

whats up guys, i been writing my code for a simple loan calculator but i keep getting errors, every thing seems fine except the formula part.. heres the code
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
#include <iostream>
#include <cmath>
#include <math.h>

using namespace std;

int main()
{
	double P, R, r, t, interestRate, year;
	int mt, m = 12;

	cout<<"Enter yearly interest rate: ";
	cin>>r;
	
	interestRate = r/100;//interest rate in decimal

	cout<<"Enter number of the year that you would like to pay off the loan: ";
	cin>>t;


	cout<<"Enter loan amount: ";
	cin>>P;

	
	R = (P/1)-(1+r/m)^(-mt);//formula
	mt = pow((1+r/m),(-m*t));//formula

	cout<<"The monthly payment is "<<R<<endl;

		
	cout<<"The total payment: "<< R*12*t <<endl;

	
	cout<<"The interest paid: "<< R - P <<endl;	

	
	system("pause");
	return 0;

}

any help is appreciated
-thanks.
I see that use use mt before you calculate mt. Surely you should be calculating it before you use it? If your compiler is paying attention, it should have warning you about using an uninitialised variable.

(P/1) is the same as P, so unless your formula really does like to divide things by one, this deserves double-checking.
Last edited on
does the formula seems right? because i cant make it to work... i have tried different ways and no luck...
i am going to start from scratch.. and see what happens
ok it worked is nothing like the original thought, here is the code
monthlyPayment = loanAmount / ((1 - pow((1+ r/m),(-m*years))) / (r/m));//Formula
r is rate in decimal
m is 12
years is the loan term in years
Topic archived. No new replies allowed.