Coder Profile - Show off your skills, get a coder profile.
 
 
 
code pin board Simple calc Download Source Code
Author Details Code Information
vozzy ( sam )

Pinned 2 Codes
Posted 0 Coding Articles

Send A Message
View Coders Profile
Language PHP (Hypertext Preprocessor)
Expires Never
Length 1,054 Characters (50 Lines)
Password no password
Description

I used the source from a previously posted code and made it better. i hope you enjoy.
to use, just upload as "calculator.php"
  1. <html>
  2. <body>
  3. <h2>Calculator</h2>
  4. This calculator only supports 4 main functions: * / + - (multiply, divide, plus, and minus)
  5. <form action="calculator.php" method="post">
  6. <input type="text" size="15" name="num1" />
  7. <select name="function">
  8.    <option value="*">*</option>
  9.    <option value ="/">/</option>
  10.    <option value ="+">+</option>
  11.    <option value ="-">-</option>
  12. </select>
  13. <input type="text" size="15" name="num2" />
  14. <label>=</label>
  15. <input type="submit" value="Calculate" />
  16. </form>
  17.  
  18.  
  19. <?php
  20. $answer = "";
  21. if (isset($_POST["num1"]) && isset($_POST["function"]) && isset($_POST["num2"])) {
  22. $num1 = $_POST["num1"];
  23. $num2 = $_POST["num2"];
  24. $function = $_POST["function"];
  25.  
  26. if ($function == "*") {
  27.    $answer = $num1 * $num2;
  28. }
  29. else if ($function == "/" && $num2 !=0) {
  30.    $answer = $num1 / $num2;
  31. }
  32. else if ($function == "+") {
  33.    $answer = $num1 + $num2;
  34. }
  35. else if ($function == "-") {
  36.    $answer = $num1 - $num2;
  37. }
  38. else {
  39. $answer = "Invalid input";
  40. }
  41. }
  42.  
  43. print "<br />";
  44. print $answer;
  45.  
  46. ?>
  47.  
  48. </body>
  49. </html>
code pin board Back To Code Pin Board Post New Code
Please login to post comments.
Page 1 of 1
 
 
Part of the MyPingle Network
Development Blog :: Make A Donation :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents
Version 1.44.00
Copyright © 2007 - 2008, Scott Thompson, All Rights Reserved