Newer
Older
Microsoft / loan / loan.c
@tundra tundra on 24 May 2012 4 KB Initial revision
From UICVM.UIC.EDU!INDYCMS.BITNET!COHERENT  Sat Jan 18 12:08:38 1992 remote from clout
Received: by eskimo.chi.il.us (smail2.5-coherent) id AA00378; 18 Jan 92 12:08:38 
Received: by clout.chi.il.us (/\==/\ Smail3.1.25.1 #25.2)
	id <m0l5EM3-000542C@clout.chi.il.us>; Sat, 18 Jan 92 05:36 CST
Message-Id: <m0l5EM3-000542C@clout.chi.il.us>
Received: from UICVM by UICVM.UIC.EDU (IBM VM SMTP V2R1) with BSMTP id 8127;
   Sat, 18 Jan 92 05:35:53 CST
Received: from UICVM.BITNET by UICVM (Mailer R2.07) with BSMTP id 1875; Sat, 18
 Jan 92 05:35:48 CST
Date:         Fri, 17 Jan 1992 20:00:53 GMT
Reply-To:     "Coherent operating system" <COHERENT%INDYCMS.bitnet@UICVM.UIC.EDU>
Sender:       "Coherent operating system" <COHERENT%INDYCMS.bitnet@UICVM.UIC.EDU>
From:         Mike Willett <mike%ARRAY.COM@UICVM.UIC.EDU>
Subject:      Source file "loan.c"
Comments: To: coherent@indycms.iupui.edu
To:           Multiple recipients of list COHERENT <COHERENT@INDYCMS>

Since the interest rates have been falling here in the States, and many
people (such as myself) want to take advantage of this money saver, I
made some minor changes to this program I have had around forever so
that it would run on Coherent. Don't hold me to the accuracy of the
output, it could be improved by a super C hack, but, it is good enough
for most of us to get an excellent idea what the loan payments would be...

Enjoy and best regards!  Kom-sa-hom-ni-da!

--Mike


/*
 * Note to Coherent Users:  compile with:
 *                                cc -o loan loan.c -f -lm
 *  --Mike
 *
 * loan.c
 * @(#) loan.c amoritization program
 *
 * acronym:    loan amortization program
 *             ----
 *
 * purpose:	calculates monthly payment, future value
 *		and creates an amortization schedule
 *
 * 06/27/84	Bill Gregg, Informatics General Corp.
 * 07/12/84     Revision 1
 * 07/12/84	Revision 2
 * 11/05/85	Jane Medefesser, Implementation NPSN Unix (wilbur)
 *		compile as follows: 'cc -o <outfile> loan.c -lm'
 * 12/05/85	Changes to direct output to a file.
 * 03/02/88	Implemented on Eternity 5.3.1
 * 01/15/92	Mike Willett, added P&I field and pause function
 * 		and minor library changes to port to Coherent
 *                     (compile with   cc -o loan loan.c -f -lm)
 */

#include <stdio.h>
#include <math.h>

/*
 *
 */

main() 		/* loan program */
{
	float amt, term, rate, ic, total;
	float r, temp, pmt, fv;
	float exp, prin, x, y, mbeg, mnbr, yrint = 0;
	int month, i, k, a = 0, yr=1;
	char d, filename[9], c;
	FILE *fp;




	/*  prompt for input from terminal  */

	printf("Enter principal amount: ");
	scanf("%f", &amt);

	printf("Enter term in years: ");
	scanf("%f", &term);

	printf("Enter interest rate in percent: ");
	scanf("%f", &rate);

	printf("Enter month payments begin (ex: 8 = August): ");
	scanf("%f", &mbeg);

	/*  compute payment and future value  */

	r = rate/100.0;
	x = 1.0 + r/12.0;
	y = term*12.0;
	temp = (1.0 / pow(x,y));
	pmt = (amt*r/12.0) / (1-temp);
	k = term*12;
	fv = pmt*k;
	ic = fv - amt;

	printf("Do you want the report directed to a file or to the screen?");
	printf("\n[f = file / s = screen] : ");
	d = getchar();      /* This is only here to eat up the '\n' left over
			       from the last scanf. */
	d = getchar();
	switch(d) {
	     case 'f':
	     d = getchar();
	     printf("\nEnter a filename: ");
	     scanf("%s", filename);
	     while((c = getchar()) != '\n') {
	     filename[a] = c; a++; }
	     fp = fopen(filename, "w");
	     break;
	     default:
	     fp = stdout;
	     break;
	     }

	     /*  print header  */

	   fprintf(fp,"\n\t *** Amortization Schedule ***\n\n");
	   fprintf(fp,"Principal:  %.2f\n", amt);
	   fprintf(fp,"Future value:  %.2f\n", fv);
	   fprintf(fp,"Term of loan in years:  %.1f\n", term);
	   fprintf(fp,"Interest Rate:  %3.3f\n", rate);
	   fprintf(fp,"Total Interest Charge:  %.2f\n", ic);
	   fprintf(fp,"Payment:  %.2f\n", pmt);
	   fprintf(fp,"\nMONTH  PRINCIPAL        INTEREST       TOTAL PMT
 BALANCE\n");

	   /* start of loop to print amortization schedule */

	   mnbr=mbeg;
	   for (i=1; i<=k; i++) {
	      month = i;
	      exp = amt*(r/12.0);
	      yrint=yrint+exp;
	      prin = pmt-exp;
	      amt = amt-prin;
	      total = prin + exp;
	      mnbr++;
	      fprintf(fp,"%d\t %.2f\t\t %.2f\t\t %.2f\t\t
 %.2f\n",month,prin,exp,total,amt);
	      if (mnbr > 12 ) {
	      fprintf(fp,"\t\tInterest paid for year %d is %.2f\n\n",yr,yrint);
	      yr++;
		pause();
	      yrint=0;
	      mnbr=1;
              }
}
	     fprintf(fp,"\t\tInterest paid for year %d is %.2f\n\n",yr,yrint);
	     fclose(fp);
}

pause()
{

static int flag;

	if(flag!=1)
	{
	getchar(); /* Flush buffer since we are not in raw mode */
	flag=1;
	}

	printf("Press return to continue:");
	while(getchar() !='\012');
}

--
Michael Willett, mike@array.com    uupsi!monarch!mike   uunet!csn!monarch!mike
		So much fun, so little time to enjoy it...