-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharithmetic.php
More file actions
56 lines (46 loc) · 1.03 KB
/
arithmetic.php
File metadata and controls
56 lines (46 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
$a = 2;
$b = 10;
function add($a, $b){
if(is_numeric($a)&& is_numeric($b)){
return $a + $b;
}else{
return "ERROR: Both arguments must be numbers\n";
}
}
function subtract($a, $b){
if(is_numeric($a)&& is_numeric($b)){
return $a - $b;
}else{
return "ERROR: Both arguments must be numbers\n";
}
}
function multiply($a, $b){
if(is_numeric($a)&& is_numeric($b)){
return $a * $b;
}else{
return throwErrorMessage("");
}
}
function divide($a, $b){
if(is_numeric($a)&& is_numeric($b)){
return $a / $b;
}else{
return "ERROR: Both arguments must be numbers\n";
}
}
function modulus($a,$b){
if(is_numeric($a)&& is_numeric($b)){
return $a % $b;
}else{
return "ERROR: Both arguments must be numbers\n";
}
}
// Add code to test your functions here
function Test($a,$b)
{
echo '5 + 4 = ' . add(5, 4) . PHP_EOL;
echo '40 - 10 = ' . subtract(40, 10) . PHP_EOL;
echo '10 * 30 = ' . multiply(10, 30) . PHP_EOL;
echo '10 / 0 = ' . divide(10, 0) . PHP_EOL;
echo '6 % 12 =' .modulus(6, 12) . PHP_EOL;