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
#include <iostream>
#include <cmath>
#include <math.h>
usingnamespace 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;
}
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.
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