#!/usr/bin/perl
# program to calculate payment schedule for a credit card
use strict;
my $principle;
my $interestRate;
my $interestPay;
my $payment;
my $month=1;
my $totalInterest=0;
# prompt user for amount borrowed (principle), annual interest
# rate, and month payment amount
print "Enter amount borrowed ";
$principle=<STDIN>;
chomp($principle);
print "Enter annual interest rate ";
$interestRate=<STDIN>;
chomp($interestRate);
$interestRate=($interestRate/12)/100;
print "Enter month payment amount ";
$payment=<STDIN>;
chomp($payment);
# do the calculations
print "Month Interest Payment Principle \n";
print "------------------------------------- \n";
while( ($principle*(1+$interestRate))>=$payment )
{
$interestPay=$interestRate*$principle;
$totalInterest=$totalInterest+$interestPay;
printf("%-9d%10.2f%10.2f%10.2f\n",$month,$interestPay,$payment ,$principle+$interestPay-$payment);
$principle=$principle+$interestPay-$payment;
$month++;
}
$interestPay=$interestRate*$principle;
$totalInterest=$totalInterest+$interestPay;
$payment=$principle+$interestPay;
printf("%-9d%10.2f%10.2f%10.2f\n",$month,$interestPay,$payment ,0);
printf ("\n\nThe total interest paid is %-10.2f\n",$totalInterest);