-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharithmetic.php
More file actions
47 lines (43 loc) · 934 Bytes
/
arithmetic.php
File metadata and controls
47 lines (43 loc) · 934 Bytes
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
<?php
function numeric_check($a, $b, $dividing = false){
if (is_numeric($a) && is_numeric($b)){
if($b === 0 && $dividing){
echo "You cannot divide by zero\n";
return false;
}
return true;
} else {
echo "Error! Both {$a} and {$b} was not a number\n";
return false;
}
}
function add($a, $b) {
if (numeric_check($a, $b)) {
return $a + $b . PHP_EOL;
}
}
function subtract($a, $b) {
if (numeric_check($a, $b)) {
return $a - $b . PHP_EOL;
}
} // Add code here
function multiply($a, $b) {
if (numeric_check($a, $b)) {
return $a * $b . PHP_EOL;
}
}
// Add code here
function divide($a, $b) {
if (numeric_check($a, $b, true)) {
return $a / $b . PHP_EOL;
}
} // Add code here
function remainder($a, $b) {
numeric_check($a, $b);
return $a % $b . PHP_EOL;
}
echo add(19, 39);
echo subtract(11, 29);
echo multiply(100, 300);
echo divide(21, 0);
// Add code to test your functions here