#!/usr/local/bin/perl $args = $ENV{'QUERY_STRING'}; print "Content-type: text/html\n\n"; if (length($args) < 3) { print <How Long will it Last?

How Long will it Last?

Here is a new twist on the mortgage calcuator. Here you tell how much you want to spend each month, an interest rate and a loan amount, and the computer tells you how long it will take you to pay it off!


  • Beginning Balance of Loan
  • Minimum Monthly payment
  • Maximum Monthly payment
  • annual percentage rate (%) (fixed loan)
  • FullForm } else { print "Loan Length Estimations\n"; print "

    Loan Length Estimations

    \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

    \n"; print "
  • Beginning Balance of Loan: \$ $abal\n"; print "
  • Minimum monthly payment : \$ $pay1\n"; print "
  • Maximum monthly payment : \$ $pay2\n"; print "
  • Annual interest rate: $intr % \n"; print "
    \n"; $intr = $intr/1200; # convert to monthly for ($i=0; $i<2; $i++) { $mv = $abal; $mm = 0; $ti = 0; if ($i == 0) { $py = $pay1; $mt = "minimum"; } else { $py = $pay2; $mt = "maximum"; } while($mv > 0 && $mm < 1200) { $mi = $mv * $intr; $ti = $ti + $mi; $mv = $mv + $mi - $py; $mm++; } print "

    Using the $mt payment it will take"; printf("%5d months (%7.3f years) to pay off your loan

    \n", $mm, $mm/12); printf("
  • Total interest: \$ %9.2f (%9.2f average per month)\n", $ti, $ti/$mm); } }