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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.