loan payment program; novel approach

Greg Earle earle at mahendo.Jpl.Nasa.Gov
Sun Sep 25 20:27:11 AEST 1988


Here's a little program to compute loan payments (using the standard
equations for loan payments) based on Principal, Interest rate and length
of term (in months).  Nothing that hasn't been done before; just in this
case the main workhorse is a bc(1) program instead of being written in C.
I provide this for your edification, amusement, and hopefully to show
people how flexible `bc' is.  You may discover something you didn't know!
I use this all the time to figure out car loan payments for all those cars
I can't afford	:^)

Here is the `loan' Bourne Shell script:  (System V sites modify the `echo -n'
to `echo Mumble\c' as appropriate)

-----------------------------  >8  Cut here  8<  --------------------------
#!/bin/sh

echo -n Enter the amount of the Principal: ""
read P
echo -n Enter the Interest in percent: ""
read I
echo -n Enter the loan Term in months: ""
read T
echo ""
echo -n The monthly payment is \$

/usr/bin/bc << EOBC

/* 'bc(1)' program to find out the amount of an exact payment */
/* due each month for a fixed-payment-plan car loan. */

define a(i, n) {
	auto z

	z = (1 + i) ^ n
	return(z)
}

define r(i, n) {
	auto z,x
	z = i * a(i,n)
	z /= (a(i,n) - 1)
	scale=4
	x = z
	return(x)
}

define m(p, i, n) {
	auto y,z
	scale = 10
	i /= 1200
	y = p * r(i, n)
	scale = 2
	z = y * 100
	z /= 100
	return(z)
}

m($P, $I, $T)
EOBC

echo ""
exit 0
-- 
	Greg Earle		earle at Sun.COM
	Sun Microsystems	poseur!earle at mahendo.JPL.NASA.GOV
	Los Angeles Consulting	earle%mahendo at elroy.JPL.NASA.GOV
...!{cit-vax,ames}!elroy!poseur!earle	...!sun!tsunami!valley!poseur!earle



More information about the Alt.sources mailing list