Friday, August 5, 2016

Math Calculator in Perl CGI

A simple math calculator that I wrote using Perl CGI that will accept two numbers from the user and then it will compute for the sum, difference, product and quotient of the number given by our user.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

<!-- input.php -->

<html>
<head>
<title>Math Calculator in Perl</title>
</head>
<style>
  body {
   font-family: arial;
   font-size: 18px;
   font-weight: bold;
 };
</style>
<body>
<h3> Math Calculator in Perl </h3>
<table border="0">
  <tr>
    <td align="center"></td>
  </tr>
  <tr>
    <td>
      <table>
        <form method="post" action="\cgi-bin\form.pl">
        <tr>
          <td>First Number</td>
          <td><input type="text" name="val1" size="5"></td>
        </tr>
        <tr>
          <td>Second Number</td>
          <td><input type="text" name="val2" size="5"></td>
        </tr>
           <tr></td>
  <tr>
          <td></td>
 <tr></td>
 <tr></td>
          <td align="right"><input type="submit" name="submit" value="Compute"></td>
        </tr>
        </table>
      </td>
    </tr>
</table>
</body>
</html>


form.pl

#!"C:\xampp\perl\bin\perl.exe"
use CGI;
use Math::Round;

CGI::ReadParse();
$val1 = $in{'val1'};
chomp($val1);
$val2 = $in{'val2'};
chomp($val2);

$add=$val1+$val2;
$subract=$val1-$val2;
$product=$val1*$val2;
$quotient=$val1/$val2;

my $rounded = sprintf("%0.2f", $quotient);

CGI::PrintHeader();
print "content-type:text/html\n\n";
print "<HTML>";
print "<font size='5'>";
print "<br>";
print "<head><title>Math Calculator in Perl</title></head>";
print "<body style='font-family:arial;'>";
print "<h4> Math Calculator in Perl </h4>";
print "Created By: Mr. Jake R. Pomperada, MAED-IT<br>";
print "<br>";
print "The sum of $val1 and $val2 is $add.<br>";
print "The difference between $val1 and $val2 is $subract.<br>";
print "The product of $val1 and $val2 is $product.<br>";
print "The quotient of $val1 and $val2 is $rounded";
print "</body>\n";
print "</html>\n";


















No comments:

Post a Comment