Category : Miscellaneous Language Source Code
Archive   : AWKDEMO2.ZIP
Filename : MORTGAGE.AWK

 
Output of file : MORTGAGE.AWK contained in archive : AWKDEMO2.ZIP
# Mortgage.AWK by S. H. Moody, 09-30-89

# User enters the Initial Principal Balance, the Annual Interest Rate, and
# The Monthly Payment on one line, separated by spaces, and the Program
# outputs a table of the monthly payments split into Interest and Principal
# components, and the Remaining Unpaid Principal Balance.


function comma(x) {
len = length(x);
dot = index(x, ".");
lastint = (dot > 0) ? dot - 1: len;
numcom = int( (lastint - index(x, "-") - 1) / 3 );
nextcom = lastint - 3 * numcom;
out = substr(x, 1, nextcom);
while (nextcom < lastint) {
out = out "," substr(x, nextcom + 1, 3) ;
nextcom +=3;
}
return out substr(x, lastint + 1);
}

BEGIN {
print"Enter Principal, Annual Interest Rate in %, and Monthly Payment: "
}

# Main

{
if(NF != 3)
next;
prinbal = $1;
ir = $2 / 12 # convert to monthly % rate
monpay = $3
print ""
print" New"
print"Pmt Monthly Principal Pmt"
print"No. Payment Interest Principal Balance No."
print"--- ---------- ---------- ---------- ---------- ---"
exit;
}


END {
while( prinbal > 0) {
n++
inter = int( prinbal * ir + 0.5) / 100;
prin = monpay - inter;
prinbal-= prin
if(prinbal <= 0) {
monpay+= prinbal;
prin+= prinbal;
prinbal = 0;
}
printf("%3d %10s %10s %10s %10s %3d\n",
n, comma(sprintf("%.2f", monpay)), comma(sprintf("%.2f",inter)),
comma(sprintf("%.2f",prin)), comma(sprintf("%.2f",prinbal)), n);

}
}


  3 Responses to “Category : Miscellaneous Language Source Code
Archive   : AWKDEMO2.ZIP
Filename : MORTGAGE.AWK

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/