campo-sirio/src/gfm/demo17.c
mtollari 1b14ec9415 Spostamento cartella sorgenti
git-svn-id: svn://10.65.10.50/branches/R_10_00@23236 c028cbd2-c16b-5b4b-a496-9718f37d4682
2016-09-09 13:59:02 +00:00

45 lines
793 B
C
Executable File

#include <stdio.h>
#include "gm.h"
void getdec(char *,DEC *);
void main(void);
void main()
{
int nper, nyear, opt, begend;
DECP pv, pmt, fv, intr, aintr;
DEC *p;
printf("Monthly payment computation\n");
getdec("Purchase price: ", pv);
getdec("Percentage annual interest rate: ", aintr);
printf("Length of loan (years): ");
dscanf("%d", &nyear);
nper = nyear * 12;
ZeroDecimal(fv);
DivideDecimalByInt(intr, aintr, 12);
opt = GM_PMT;
begend = GM_END;
p = CompoundInterest(&nper, intr, pv, pmt, fv, begend, opt);
if (p) {
AbsoluteDecimal(pmt, pmt);
dprintf("The monthly payment is %v\n", pmt);
}
else
dprintf("CompoundInterest failed\n");
}
void getdec(str, x)
char *str;
DEC *x;
{
int i;
do {
printf("%s", str);
i = dscanf("%t", x);
} while (i<1);
}