-
Notifications
You must be signed in to change notification settings - Fork 0
/
rechne.php
47 lines (41 loc) · 901 Bytes
/
rechne.php
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 rechne ($wert1,$operator,$wert2){
switch ($operator) {
case '+':
$wert=$wert1+$wert2;
return $wert;
break;
case '-':
$wert=$wert1-$wert2;
return $wert;
break;
case '/':
if ($wert2==0){
return 'Wer 2 ist Null! Nicht möglich!';
}
else{
$wert=$wert1/$wert2;
return $wert;
break;
}
case '*':
$wert=$wert1*$wert2;
return $wert;
break;
case '%':
$wert=$wert1%$wert2;
return $wert;
break;
default:
echo "<br>Kein Bekanntes Rechenparameter mögliche Parameter: +,-,/,*,%<br><br>";
}
}
echo '5+2='.rechne(5,'+',2).'<br>';
echo '5-3='.rechne(5,'-',3).'<br>';
echo '5*3='.rechne(5,'*',3).'<br>';
echo '4/2='.rechne(4,'/',2).'<br>';
echo '5%2='.rechne(5,'%',2).'<br>';
echo '5x3='.rechne(5,'x',3).'<br>';
echo '5/0='.rechne(5,'/',0).'<br>';
echo '0/5='.rechne(0,'/',5).'<br>';
?>