#!/usr/local/bin/perl $args = $ENV{'QUERY_STRING'}; print "Content-type: text/html\n\n"; if (length($args) < 3) { print <Loan Length Calculator

Loan Length Calculator

Enter how much you want to spend each month, an interest rate and a loan amount, and the calculator will tell you how long it will take you to pay off the loan!

Beginning Balance of Loan
Minimum Monthly payment
Maximum Monthly payment
APR (%) (fixed loan)

FullForm } else { print "Loan Length Calculator\n"; print ""; print "

Loan Length Calculator Results

\n"; # Let's do the calculations! @va = split("&",$args); for ($i=0; $i<7; $i++) { @va[$i] = substr(@va[$i],5); } ($abal,$pay1,$pay2,$intr) = @va; print "

Inputs: To re-calculate the scenario change the following inputs and press re-calculate.\n"; printf(<
Beginning Balance of Loan
Minimum Monthly payment
Maximum Monthly payment
APR (%) (fixed loan)

FormFull $intr = $intr/1200; # convert to monthly print<  Loan LengthAvg. Monthly InterestTotal Interest tableHeader for ($i=0; $i<2; $i++) { $mv = $abal; $mm = 0; $ti = 0; if ($i == 0) { $py = $pay1; $mt = "Minimum Payment"; } else { $py = $pay2; $mt = "Maximum Payment"; } while($mv > 0 && $mm < 1200) { $mi = $mv * $intr; $ti = $ti + $mi; $mv = $mv + $mi - $py; $mm++; } printf(<$mt%5d months (%7.3f years)\$ %9.2f%9.2f showMyResults } print "
" }