rjangelov

ArraysInPHP - //Problem 6. **Simple calculator

Jun 25th, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. //Problem 6.    **Simple calculator
  2. //Write a script that read two input number from user and choose operands. Put appropriate validation of input lines calculate and print //result on output line.
  3. <!DOCTYPE html>
  4. <html>
  5.     <head>
  6.         <meta charset="UTF-8">
  7.         <title></title>
  8.     </head>
  9.     <body>
  10.         <form action="SimpleCalculator.php" method="post">
  11.         <input type="text" name="num1">
  12.         <select name="operation">
  13.             <option value="plus">+</option>
  14.             <option value="minus">-</option>
  15.             <option value="multiplication">*</option>
  16.             <option value="divide">/</option>
  17.         </select>
  18.         <input type="text" name="num2">
  19.         <input type="submit" value="enter!">
  20.         </form>
  21.     </body>
  22. </html>
  23. <?php
  24. $num1 = $_POST['num1'];
  25. $num2 = $_POST['num2'];
  26. $operation=$_POST['operation'];
  27. if ($operation=="plus") {
  28.     echo $num1+$num2;
  29. }
  30. elseif ($operation=="minus") {
  31.     echo $num1-$num2;
  32. }
  33. elseif ($operation=="multiplication") {
  34.     echo $num1*$num2;
  35. }
  36. elseif ($operation=="divide") {
  37.     echo $num1/$num2;
  38. }
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment