This tutorial ,I have included some of the mathematical functions which could not be included in tutorial simple calculator.although some of number conversion is included here completed number conversion is included in next tutorial.
Calculator2 interface is bellow.Number | ||
Operation:- | Bin_DEC | Dec_Hex |
Dec_Oct | Dec_Bin | |
Round | Oct_Dec | |
√ | 1/x | |
X2 | % | |
∏ | C | |
Cos | Sin | |
Tan | ||
<table bgcolor=#d38a2a> <form name="calc" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <tr bgcolor=#ffffff><td>Number </td><td><input type="text" name="value1"><td align="center"><img src="cal.png"></td></tr> <tr bgcolor=#ffffff><td>Operation:-</td><td><input type="radio" name="oper" value="bdec">Bin_DEC</td><td><input type="radio" name="oper" value="dhex">Dec_Hex</td></tr> <tr bgcolor=#ffffff><td> </td><td><input type="radio" name="oper" value="doct">Dec_Oct</td><td><input type="radio" name="oper" value="dbin">Dec_Bin</td></tr> <tr bgcolor=#ffffff><td> </td><td><input type="radio" name="oper" value="rd">Round</td><td><input type="radio" name="oper" value="odec">Oct_Dec</td></tr> <tr bgcolor=#ffffff><td> </td><td><input type="radio" name="oper" value="sqr">√</td><td><input type="radio" name="oper" value="inv">1/x</input></td></tr> <tr bgcolor=#ffffff><td> </td><td><input type="radio" name="oper" value="powd">X<sup>2</sup></td><td><input type="radio" name="oper" value="per">%</td></tr> <tr bgcolor=#ffffff><td> </td><td><input type="radio" name="oper" value="pi">∏</td><td><input type="radio" name="oper" value="reset">C</td></tr> <tr bgcolor=#ffffff><td> </td><td><input type="radio" name="oper" value="cos">Cos</td><td><input type="radio" name="oper" value="sin">Sin</td></tr> <tr bgcolor=#ffffff><td> </td><td><input type="radio" name="oper" value="tan">Tan</input></td><td> </td></tr> <tr bgcolor=#ffffff><td colspan=3 align="right"><input type="submit" value="Calculate"></td></tr> </form> </table> <?php $number1=$_POST['value1']; $oper=$_POST['oper']; if($oper=='bdec'){ echo bindec("$number1"); } else if($oper=='dhex'){ echo dechex("$number1"); } else if($oper=='doct'){ echo decoct("$number1"); } else if($oper=='dbin'){ echo decbin("$number1"); } else if($oper=='rd'){ echo round("$number1"); } else if($oper=='odec'){ echo octdec("$number1"); } else if($oper=='sqr'){ echo sqrt("$number1"); } else if($oper=='inv'){ $result=1/$number1; echo $result; } else if($oper=='powd'){ $result=$number1*$number1; echo $result; } else if($oper=='per'){ $result=$number1/100; echo $result; } else if($oper=='pi'){ echo pi(); } else if($oper=='reset'){ echo "field is cleared"; } else if($oper=='cos'){ echo cos($number1); } else if($oper=='sin'){ echo sin($number1); } else if($oper=='tan'){ echo tan($number1); } else { echo "<font color='red'>Wrong Input or Method</font>"; } ?> |
No comments:
Post a Comment