Advertisement
ShadowEmbrace

Calculations

Oct 22nd, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. <?php
  2.  
  3. $command = strtolower(readline());
  4. $a = intval(readline());
  5. $b = intval(readline());
  6.  
  7. switch ($command){
  8.     case 'add':
  9.         $sum = printAdd($a, $b);
  10.         echo $sum;
  11.         break;
  12.     case 'multiply':
  13.          echo printMultiply($a, $b);
  14.         break;
  15.     case 'subtract':
  16.         printSubtract($a, $b);
  17.         break;
  18.     case 'divide':
  19.         printDivide($a, $b);
  20.         break;
  21. }
  22.  
  23. function printAdd($num1, $num2){
  24.     $result = $num1 + $num2;
  25.     return $result;
  26. }
  27. function printMultiply($num1, $num2){
  28.     $result = ($num1 * $num2);
  29.     return $result;
  30. }
  31. function printSubtract($num1, $num2){
  32.     echo ($num1 - $num2);
  33. }
  34. function printDivide($num1, $num2){
  35.     echo ($num1 / $num2);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement