All pastes #2090306 Raw Edit

Unnamed

public text v1 · immutable
#2090306 ·published 2011-10-15 14:39 UTC
rendered paste body
#!/usr/bin/env perl

use strict;
use warnings;

@ARGV == 3
    or die "Usage: $0 current-total  interest-rate  days\n";

my ( $current_total, $interest_rate, $days ) = @ARGV;

my $original_total = $current_total;
for ( 0 .. $days ) {
    my $interest = ( $current_total * ( $interest_rate / 100 ) ) / 365;
    printf "On day %d we add %.2f interest to the %.2f total, which gives us %.2f\n",
            $_, $interest, $current_total, $current_total + $interest;

    $current_total += $interest;
}

printf "--\nAfter $days days you would pay \$%.2f of interest, making the total %.2f\n",
            $current_total - $original_total, $current_total;