-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
90 lines (74 loc) · 2.09 KB
/
index.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Calculator</title>
</head>
<body>
<h3>Добро пожаловать в простое приложение <i>калькулятор</i></h3>
<form action="" method="get">
<p>
<label>Первое число
<input type="number" name="f_number" placeholder="Введите число">
</label>
</p>
<p>
<label>Второе число
<input type="number" name="s_number" placeholder="Введите число">
</label>
</p>
<p>
<label>Выберите действие:</label>
<select name="action" id="">
<option value="+">+</option>
<option value="-">-</option>
<option value="/">/</option>
<option value="*">*</option>
</select>
</p>
<button type="submit" value="count">Посчитать</button>
</form>
<?php
$f_number = $_GET['f_number'];
$s_number = $_GET['s_number'];
if($s_number == 0){
die ("На ноль делить нельзя!");
}
$operation = $_GET['action'];
function sum($x,$y){
$res = $x + $y;
return $res;
}
function diff($x,$y){
$res = $x - $y;
return $res;
}
function mult($x,$y){
$res = $x * $y;
return $res;
}
function div($x,$y){
$res = $x / $y;
return $res;
}
function mathOperation($arg1, $arg2, $operation){
switch($operation){
case "+":
return sum($arg1, $arg2);
break;
case "-":
return diff($arg1, $arg2);
break;
case "*":
return mult($arg1, $arg2);
break;
case "/":
return div($arg1, $arg2);
break;
}
}
$result = mathOperation($f_number, $s_number, $operation);
echo "$f_number $operation $s_number" . " = " . "$result";
?>
</body>
</html>