54 lines
1.1 KiB
C
54 lines
1.1 KiB
C
|
#include <stdio.h>
|
||
|
#include "gm.h"
|
||
|
void getdec(char *,DEC *);
|
||
|
void main(void);
|
||
|
static DEC *payintr[500], *payprin[500], *balance[500];
|
||
|
|
||
|
void main()
|
||
|
{
|
||
|
int nper, nyear, begend, i;
|
||
|
DECP pv, pmt, intr, aintr;
|
||
|
extern DEC *payintr[500], *payprin[500], *balance[500];
|
||
|
|
||
|
printf("Amortization schedule\n");
|
||
|
|
||
|
getdec("Amount of loan (positive): ", pv);
|
||
|
getdec("Percentage annual interest rate: ", aintr);
|
||
|
printf("Length of loan (years): ");
|
||
|
dscanf("%d", &nyear);
|
||
|
getdec("Monthly payment (positive): ", pmt);
|
||
|
|
||
|
nper = nyear * 12;
|
||
|
DivideDecimalByInt(intr, aintr, 12);
|
||
|
begend = GM_END;
|
||
|
|
||
|
AllocateDecimalArray(payintr, nper+1);
|
||
|
AllocateDecimalArray(payprin, nper+1);
|
||
|
AllocateDecimalArray(balance, nper+1);
|
||
|
|
||
|
AmortizeTable(payintr, payprin, balance, intr,
|
||
|
pv, pmt, begend, nper);
|
||
|
|
||
|
printf("%15s%20s%20s%20s\n", "Payment #", "Interest",
|
||
|
"Principal", "Balance");
|
||
|
for (i=1; i<=nper; i++)
|
||
|
dprintf("%15d%20v%20v%20v\n", i, payintr[i],
|
||
|
payprin[i], balance[i]);
|
||
|
|
||
|
FreeDecimalArray(payintr);
|
||
|
FreeDecimalArray(payprin);
|
||
|
FreeDecimalArray(balance);
|
||
|
}
|
||
|
|
||
|
void getdec(str, x)
|
||
|
char *str;
|
||
|
DEC *x;
|
||
|
{
|
||
|
int i;
|
||
|
|
||
|
do {
|
||
|
printf("%s", str);
|
||
|
i = dscanf("%t", x);
|
||
|
} while (i<1);
|
||
|
}
|