| Category: | Miscellaneus |
| Author/Contact Info | contact me: /msg sulfericacid |
| Description: | Based on principle, interest and duration this finds your monthly payments. Along with the answer the script shows you the actual equation and walks you through the steps of solving the problem. To my knowledge this is accurate (my smarter older brother gave me the equation) but if you find this to be inaccurate please give me the proper equation so I can fix this! UPDATE: A rough CGI version was written and can be found below. |
Command Line Version
-----------------------
#!/usr/bin/perl -w
use strict;
use warnings;
my ( $totalinterest, $totaldue, $monthlypayment, $round );
print "Principle:";
chomp( my $principle = <STDIN> );
while ( $principle !~ /^-?\.?\d+(?:\.\d+)?$/ ) {
print "Number you supplied did not look like a real number.\n";
print "Only numbers and decimals are allowed, no commas!\n\n";
print "Principle:";
chomp( $principle = <STDIN> );
}
print "Interest (as a decimal):";
chomp( my $interest = <STDIN> );
while ( $interest !~ /^-?\.?\d+(?:\.\d+)?$/ ) {
print "Number you supplied did not look like a real number.\n";
print "Only numbers and decimals are allowed, no commas!\n\n";
print "Interest (as a decimal):";
chomp( $interest = <STDIN> );
}
print "Duation (in months):";
chomp( my $duration = <STDIN> );
while ( $duration !~ /^-?\.?\d+(?:\.\d+)?$/ ) {
print "Number you supplied did not look like a real number.\n";
print "Only numbers and decimals are allowed, no commas!\n\n";
print "Interest (as a decimal):";
chomp( $duration = <STDIN> );
}
print "\n---------------------------\n";
$totalinterest = $principle * $interest;
print "Total interest: \$$totalinterest\n";
$totaldue = $totalinterest + $principle;
print "Total due: \$$totaldue\n";
$monthlypayment = $totaldue / $duration;
$round = sprintf "%.2f", $monthlypayment;
print "Monthly price: \$$round\n";
print "---------------------------\n\n";
print "How we did it:\n";
print "Actual equation: (principle * interest + principle) / months\n"
+;
print "Your equation: ($principle \* $interest \+ $principle) \/ mon
+ths\n";
print "Step one: ($totalinterest \+ $principle) \/ months\n";
print "Step two: ($totaldue) \/ months\n";
print "Step three: $round";
CGI Version
---------------------
#!/usr/bin/perl -w
use strict;
use warnings;
my ( $totalinterest, $totaldue, $monthlypayment, $round );
use CGI qw/:standard/;
print header, start_html(), start_form, "Principle (amount due): ",
textfield('principle'), p, "Interest (as a decimal): ", textfield('i
+nterest'),
p, "Duration (in months): ", textfield('duration'), p, submit, end_f
+orm, hr;
chomp( my $principle = param('principle') );
chomp( my $interest = param('interest') );
chomp( my $duration = param('duration') );
if ( $principle && $interest && $duration ) {
# if (param('principle') && param('interest') && param('duration
+')) {
print "\n---------------------------<br>";
$totalinterest = $principle * $interest;
print "Total interest: \$$totalinterest<br>";
$totaldue = $totalinterest + $principle;
print "Total due: \$$totaldue<br>";
$monthlypayment = $totaldue / $duration;
$round = sprintf "%.2f", $monthlypayment;
print "Monthly price: \$$round<br>";
print "---------------------------<br><br>";
print "How we did it:<br>";
print "Actual equation: (principle * interest + principle) / month
+s<br>";
print "Your equation: ($principle \* $interest \+ $principle) \/
+ $duration<br>";
print "Step one: ($totalinterest \+ $principle) \/ $duratio
+n<br>";
print "Step two: ($totaldue) \/ $duration<br>";
print "Step three: \$$round";
hr;
}
else {
print "Something was missing!<br>";
}
print end_html();
|
|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Monthly Payment Analyzer (formulas)
by tye (Sage) on Apr 01, 2003 at 18:51 UTC | |
by sulfericacid (Deacon) on Apr 01, 2003 at 19:11 UTC | |
by tye (Sage) on Apr 01, 2003 at 20:16 UTC | |
by clscott (Friar) on Apr 01, 2003 at 19:47 UTC |