{"id":5464,"date":"2014-09-10T21:56:43","date_gmt":"2014-09-10T21:56:43","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=5464"},"modified":"2014-09-28T23:24:43","modified_gmt":"2014-09-28T23:24:43","slug":"perl-programming-a-compound-interest-calculator-part-i","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/perl-programming-a-compound-interest-calculator-part-i\/","title":{"rendered":"Perl programming:  a compound interest calculator, part I"},"content":{"rendered":"<h1>The tutor continues his coverage of programming with Perl. \u00a0Today, we&#8217;ll look at some math operators.<\/h1>\n<p>Over the summer, I covered beginners&#8217; aspects of Perl programming. \u00a0 Searching this blog for perl, or else choosing the computer science category on the right pane, should point you towards the articles.<\/p>\n<p>Back in February 2013, I covered <a href=\"?p=1441\">compound interest<\/a>. Today&#8217;s article continues in that direction as well, with a Perl programming example.<\/p>\n<p>The following program calculates the future value of an investment. The user provides the principal amount, the interest rate, and the time duration when calling the program from the command line.<br \/>\n<span style=\"color: brown; font-family: monospace;\"><br \/>\n#!\/usr\/bin\/perl<br \/>\n$principal =$ARGV[0];<br \/>\n$percent=$ARGV[1];<br \/>\n$rate=$ARGV[1]\/100;<br \/>\n$time=$ARGV[2];<br \/>\n$futurevalue=$principal*(1+$rate)**$time;<br \/>\nprint &#8220;The principal amount is $principal\\n&#8221;;<br \/>\nprint &#8220;The annual interest rate is $percent percent\\n&#8221;;<br \/>\nprint &#8220;The time duration of the investment is $time\\n\\n&#8221;;<br \/>\nprint &#8220;The future value of the intestment is $futurevalue\\n\\n&#8221;;<br \/>\n<\/span><br \/>\nLet&#8217;s imagine you name the program <span style=\"font-family: monospace;\">intcalc.txt<\/span>, and that you want to use it to calculate the future value of an investment with<\/p>\n<p>principal=$4000<br \/>\nrate=3.5%<br \/>\ntime=21 years<\/p>\n<p>Navigating (in the terminal) to the directory that contains <span style=\"font-family: monospace;\">intcalc.txt<\/span>, you might call it from the command line as follows:<\/p>\n<p><span style=\"font-family: monospace;\">perl intcalc.txt 4000 3.5 21<\/span><\/p>\n<p>Notice the Perl division operator <span style=\"font-family: monospace;\">\/<\/span>. Of course, <span style=\"font-family: monospace;\">*<\/span> means &#8220;multiply&#8221;, while <span style=\"font-family: monospace;\">**<\/span> means &#8220;exponent.&#8221;<\/p>\n<p>As is, this program considers only annual compounding. In a future post, we&#8217;ll amend it to accommodate other possibilities.<\/p>\n<p>Cheers:)<\/p>\n<p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The tutor continues his coverage of programming with Perl. \u00a0Today, we&#8217;ll look at some math operators. Over the summer, I covered beginners&#8217; aspects of Perl programming. \u00a0 Searching this blog for perl, or else choosing the computer science category on &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/perl-programming-a-compound-interest-calculator-part-i\/\"> <span class=\"screen-reader-text\">Perl programming:  a compound interest calculator, part I<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105],"tags":[221,173],"class_list":["post-5464","post","type-post","status-publish","format-standard","hentry","category-computer-science","tag-compound-interest","tag-perl-programming"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/5464","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=5464"}],"version-history":[{"count":21,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/5464\/revisions"}],"predecessor-version":[{"id":5748,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/5464\/revisions\/5748"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=5464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=5464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=5464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}