Friday, December 11, 2009

Simple Calculator Online

Simple Calculator Online
Hello again coding freak...Back again with PHP Tutorial. PHP has some mathematical functions that can be used to count. Through this tutorial I will teach you how to make a simple calculator online.








First, create a file and name it "calculator.html" and then type the following command:



<html>
<head>
<title>Simple Calculator Online</title>
</head>
<body>
<form name="form1" method="post" action="count.php">
<p>Mathematical Operators</p>
<p>
<input name="angka" type="text" id="angka">
<select name="operator" id="operator">
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select>
<input name="angka2" type="text" id="angka2"> 
<input type="submit" name="Submit" value="Calculate">
</p>
</form>
<form name="form2" method="post" action="count2.php">
<p>Mathematical Constants</p>
<p>
<input name="angka" type="text" id="angka">
<select name="operator" id="operator">
<option>abs</option>
<option>floor</option>
      <option>round</option>
      <option>decbin</option>
      <option>bindec</option>
      <option>decoct</option>
      <option>octdec</option>
      <option>dechex</option>
      <option>hexdec</option>
      <option>sin</option>
      <option>cos</option>
      <option>tan</option>
      <option>log</option>
      <option>sqrt</option>
    </select>
    <input type="submit" name="Submit" value="Hitung">
</p>
  <p>Keterangan :</p>
  <table width="100%"  border="0">
    <tr>
      <td>+</td>
      <td>=</td>
      <td>Plus.</td>
    </tr>
    <tr>
      <td>-</td>
      <td>=</td>
      <td>Minus.</td>
    </tr>
    <tr>
      <td>*</td>
      <td>=</td>
      <td>Multiple.</td>
    </tr>
    <tr>
      <td>/</td>
      <td>=</td>
      <td>Divide.</td>
    </tr>
    <tr>
      <td width="4%">abs</td>
      <td width="2%">=</td>
      <td width="94%">Returns the absolute value of number .</td>
    </tr>
    <tr>
      <td>floor</td>
      <td>=</td>
      <td>Returns the next lowest integer value by rounding down value if necessary. </td>
    </tr>
    <tr>
      <td>round</td>
      <td>=</td>
      <td>Returns the rounded value of val to specified precision (number of digits after the decimal point).  </td>
    </tr>
    <tr>
      <td>decbin</td>
      <td>=</td>
      <td>Convert an integer to binary number. </td>
    </tr>
    <tr>
      <td>bindec</td>
      <td>=</td>
      <td>Convert a binary number to an integer. (opposite of decbin) </td>
    </tr>
    <tr>
      <td>decoct</td>
      <td>=</td>
      <td>Convert an integer to an octal. </td>
    </tr>
    <tr>
      <td>octdec</td>
      <td>=</td>
      <td>Convert an octal to an integer (opposite of decoct) </td>
    </tr>
    <tr>
      <td>dechex</td>
      <td>=</td>
      <td>Convert an integer to a Hexadesimal. </td>
    </tr>
    <tr>
      <td>hexdec</td>
      <td>=</td>
      <td>Convert a Hexadecimal to an integer (opposite of dechex). </td>
    </tr>
    <tr>
      <td>sin</td>
      <td>=</td>
      <td>sine</td>
    </tr>
    <tr>
      <td>cos</td>
      <td>=</td>
      <td>cosine</td>
    </tr>
    <tr>
      <td>tan</td>
      <td>=</td>
      <td>tangent</td>
    </tr>
    <tr>
      <td>log</td>
      <td>=</td>
      <td>log</td>
    </tr>
    <tr>
      <td>sqrt</td>
      <td>=</td>
      <td>Returns the square root of arg</td>
    </tr>
  </table>
</form>
<p>&nbsp;</p>
</body>
</html>




Then for the second, create a file with the name "count.php" and type the following script :


<?php
$number = $_POST['number'];
$number2 = $_POST['number2'];
$operator = $_POST['operator'];
if ($operator == '+')
{
$output = $number+$number2;
}
if ($operator == '-')
{
$output = $number-$number2;
}
if ($operator == '*')
{
$output = $number*$number2;
}
if ($operator == '/')
{
$output = $number/$number2;
}

print "$output";
?>



And for the last, create a file with the name "count2.php" and then type the following script:


<?php
$number = $_POST['number'];
$operator = $_POST['operator'];
if ($operator == 'abs')
{
$output = abs($number);
}
if ($operator == 'floor')
{
$output = floor($number);
}
if ($operator == 'round')
{
$output = round($number);
}
if ($operator == 'decbin')
{
$output = decbin($number);
}
if ($operator == 'bindec')
{
$output = bindec($number);
}
if ($operator == 'decoct')
{
$output = octdec($number);
}
if ($operator == 'octdec')
{
$output = octdec($number);
}
if ($operator == 'dechex')
{
$output = dechex($number);
}
if ($operator == 'hexdec')
{
$output = hexdec($number);
}
if ($operator == 'sin')
{
$output = sin($number);
}
if ($operator == 'cos')
{
$output = cos($number);
}
if ($operator == 'tan')
{
$output = tan($number);
}
if ($operator == 'log')
{
$output = log($number);
}
if ($operator == 'sqrt')
{
$output = sqrt($number);
}
print "$output";
?>


That's all....you may try it...

Related Posts by Categories



0 comments:

Post a Comment

Maybe this is what you looking for

 

Subscribe Now

Followers

IT Skill is not enough... Copyright © 2009 Designed by Bie Blogger Template