Sorry, I should have said 'principal' instead of "principle'. Which are the confusing terms?
Sorry, I should have said 'principal' instead of "principle'. Which are the confusing terms?
Your code's formula does not match the "given" formula. You're missing a "1+" term it seems.
How about:
Code:#define LOAN_PRINCIPAL 0 #define LOAN_RATE 1 #define LOAN_TERM 2 payment = (myarray[LOAN_PRINCIPAL] * myarray[LOAN_RATE] / 100 ) / (1 - ( pow (1 + myarray[LOAN_RATE], -myarray[LOAN_TERM] ) ) );
Do you need floating point math, or can you get away with integer? (There are tricks to use)
Is rate given in decimal (0.05) or percent (5)?
mike65535, I have already given the correct formular incoporating the 1 +
I would assume it's given as decimal 0.05, because that way the (1 + percent)^(-num_payments) makes sense.
Yup, as I thought. You need to get this straight - what your requirements are for input and what you are allowed (or forced to) to do within the code.
Even if you can use float, I suggest you essentially use integers * 100 so that you can get exact pennies. (or not...)
Last edited by mike65535; 04-18-2011 at 02:32 PM.
I DON'T THINK SO!
On this page they give your formula...
Mortgage calculator - Wikipedia, the free encyclopedia
The fixed monthly payment for a fixed rate mortgage is the amount paid by the borrower every month that ensures that the loan is paid off in full with interest at the end of its term. The monthly payment formula is based on the annuity formula. The monthly payment c depends upon:
r - the monthly interest rate, expressed as a decimal, not a percentage (i.e., divide the quoted yearly percentage rate by 100 and then by 12 to obtain the monthly interest rate),
N - the number of monthly payments, called the loan's term, and
P - the amount borrowed, known as the loan's principal.
c is given by the formula:
Well as of now I can't do anything. Since my I'm going to have to use pow(), I need to convert my code to double. However, doing so doesn't seem to be producing the same output I want (as in, it produces nothing. or causes my program to see any number entered to be invalid and out of range. This sucks.
EDIT: Now it's working slightly better. I should be able to work with the actual math of it now.
Last edited by NinjaFish; 04-18-2011 at 02:34 PM.
The calculations for amortizing a loan are not secret, so I'll post a simple program that does a simple amortization table. You'll need to incorporate this into the program you're trying to write (i.e. the arrays).
Good luck!Code:#include <stdio.h> #include <math.h> int main( void ) { double principal = 10000.0; double annualRate = 12.0; double rate = annualRate / ( 12 * 100 ); int termYears = 5; int termMonths = termYears * 12; double payment = principal * ( rate / ( 1 - pow( ( 1 + rate ), -termMonths ) ) ); int month; for ( month = 1; month <= termMonths; month++ ) { double monthlyInterest = principal * rate; double monthlyPrincipal = payment - monthlyInterest; double newPrincipal = principal - monthlyPrincipal; printf( "%3d::%8.2lf::%6.2lf::%6.2lf::%6.2lf::%7.2lf\n", month, principal, payment, monthlyInterest, monthlyPrincipal, newPrincipal ); principal = newPrincipal; } return 0; }
Last edited by kmess; 04-18-2011 at 02:53 PM.
How goes the battle? Any closer?