Facebook
From Pavan Sengar, 2 Years ago, written in PHP.
This paste is a reply to Basic Calculator from RealBlocks - view diff
Embed
Download Paste or View Raw
Hits: 230
  1. <?php
  2.  
  3. class Calculator
  4. {
  5.  public function add(...$numbers)
  6.  {
  7.        $total = 0;
  8.         foreach($numbers as $number){
  9.             if(is_numeric($number)){
  10.                $total += $number;
  11.             }else{
  12.                 throw new Exception ("All the number must be numeric")
  13.             }
  14.         }
  15.   return $total;
  16.  }
  17.  
  18.  public function divide($a, $b)
  19.  {
  20.   $total = 0;
  21.         if(is_numeric($a) && is_numeric($b)){
  22.           $total = $a / $b;
  23.         }else{
  24.           throw new Exception ("All the number must be numeric")
  25.         }
  26.      
  27.   return $total;
  28.  }
  29. }
  30.