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();
In reply to Monthly Payment Analyzer by sulfericacid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |