#!/usr/bin/perl my $start = $ARGV[0]; my $apr = $ARGV[1]; my $months = $ARGV[2]; my $addto = $ARGV[3]; if ($months eq "") { print "Computes monthly compounding interest.\n"; print "Usage: $0 (amount additional investment each month)\n"; exit; } if ($addto eq "") { $addto = 0; } my $mpr = $apr / 12; print "Monthly percentage rate is $mpr\n"; print "Begin: \$" . $start . "\n"; my $total_interest = 0; my $total_invested = $start; my $i = 0; my $total = $start; while($i <= $months) { unless ($i == 0) { $total = $total + $addto; $total_invested = $total_invested + $addto } my $interest = $total * $mpr; $total_interest = $total_interest + $interest; $total = $total + $interest; printf("Month %02i Added: \$%i \$%.4f interest\tTotal: \$%.2f\n",$i,$addto,$interest,$total); $i++; } printf("Done. Made \$%.2f in interest, with an investment of \$%.2f\n",$total_interest,$total_invested);