use strict; my ($discount, $months) = @ARGV; ($discount > 0 and $discount < 100 and $months >= 1 ) or die < $C){ # result is too high, need higher r $lowr = $nextr; $nextr += (rand(1) * ($highr - $lowr)) }else{ # result is too low, need lower r $highr = $nextr; $nextr -= (rand(1) * ($highr - $lowr)) } }; my $r = ($highr + $lowr) / 2; print " a $discount% discount for $months payment at a time implies an r of $r\n"; my $Month = 0; my $C2 = 9876543; print " MONTH PRINCIPAL-BEFORE PAYMENT PRINCIPAL-AFTER "; format amortization= @### @#####.#### (@#.##) @#####.#### $Month, $C, 1, $C2 . $~ = 'amortization'; while (1){ $C2 = $C - 1; $C2 < -1/24 and last; write; $C = $C2 * $e**($r * (1/12)); $Month++; };