mortgage interest calculator
Kevin Carothers
kevin at ttidca.TTI.COM
Fri Aug 11 05:32:44 AEST 1989
Hi -
I don't know if I posted this here before, but here it is anyway.
I am posting my loan-interest program that I originally posted in
"misc.consumers" a couple of years ago. Instructions are easy.
Seems like a lot of people from Europe are picking up this newsgroup,
so I can't vouch for Overseas banking interest formulae.
Any problems, let me know.
---------------------------------------------------------------------
/*
* Program to print a mortgage payment
* debt over a period of years
*/
#include <stdio.h>
main()
{
int c,i;
float mort_amt;
float mort_int;
float mort_pmt;
float intrst;
int mort_yrs;
float t_int;
float t_t;
float t_tmp;
float temp;
float tmp_amt;
float tmp_int;
int tmp_yrs;
int y_yrs;
float y_int;
float y_t;
float y_tmp;
printf("Enter the loan amount: ");
scanf("%f",&mort_amt);
printf("Enter the years of the loan: ");
scanf("%d",&mort_yrs);
tmp_yrs=mort_yrs;
printf("Enter the interest rate: ");
scanf("%f",&mort_int);
if(mort_int < 1.) mort_int *= 100.;
intrst = (mort_int/100.)/12.;
mort_yrs *= 12;
temp = 1.;
do {
temp *= (1. +intrst);
mort_pmt += (1./temp);
mort_yrs--;
} while(mort_yrs > 0);
temp = mort_amt/mort_pmt;
mort_int /= 100.;
y_tmp = y_int = y_t = 0.;
mort_yrs = 0;
tmp_amt = mort_amt;
printf("\nloan amount: $%6.2f\t\t",tmp_amt);
printf("loan rate: %4.2f%\n",mort_int*100.);
printf("monthly payment: $%10.2f\n\n",temp);
if((c=getchar()) != EOF)
if((c=getchar()) == EOF)
exit();
do {
printf("year: %d",++mort_yrs);
printf("\nloan amount: $%6.2f\t\t",tmp_amt);
printf("loan rate: %4.2f%\n",mort_int*100.);
printf("monthly payment: $%10.2f\n\n",temp);
printf("month\tpayment\t\tinterest\tprincipal\tbalance\n");
printf("-----\t-------\t\t--------\t---------\t-------\n");
t_tmp = t_int = t_t = 0.;
for(i=1 ; i <= 12 ; ++i) {
if(mort_amt <= .01) {
mort_yrs = tmp_yrs; /* force exit */;
break;
}
tmp_int = temp - (mort_amt*(mort_int/12.));
mort_amt -= tmp_int;
printf("%2d\t$%7.2f\t$%7.2f\t$%7.2f\t$%7.2f\n",
i,temp,temp-tmp_int,tmp_int,mort_amt);
t_tmp += temp;
t_t += tmp_int;
t_int +=temp-tmp_int;
y_tmp+= temp;
y_t += tmp_int;
y_int += temp-tmp_int;
}
printf(" \t_______\t\t________\t_________\n");
printf(" \t$%7.2f\t$%7.2f\t$%7.2f\n",t_tmp,t_int,t_t);
printf(" \t_______\t\t________\t_________\n");
printf(" \t$%7.2f\t$%7.2f\t$%7.2f\n",
y_tmp,y_int,y_t);
printf(" \t=======\t\t========\t=========\n");
if((c=getchar()) == EOF)
break;
} while(mort_yrs< tmp_yrs);
}
More information about the Alt.sources
mailing list