DOCTYPE html html head meta charset UTF-8 title Arifmetica title link

 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Arifmetica</title>
<link rel="stylesheet" href="arifmetica.css">
</head>
<?php
function isFormValid() {
if (isset($_POST['num1']) && isset($_POST['num2']) && isset($_POST['operation'])) {
return true;
} else {
return false;
}
}
function calculate() {
if (isFormValid()) {
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$operation = $_POST['operation'];
switch ($operation) {
case '+':
return $num1 + $num2;
case '-':
return $num1 - $num2;
case '*':
return $num1 * $num2;
case '/':
return ($num2 != 0) ? $num1 / $num2 : "Деление на 0";
default:
return "Something went wrong";
}
} else {
echo "Заполните все поля";
}
}
?>
<body>
<div class="form-box">
<form action="arifmetica.php" class="form" method="post">
<label for="num1" class="form__input-label">Number 1:</label>
<input type="number" name="num1" id="num1" class="form__input">
<label for="num2" class="form__input-label">Number 2:</label>
<input type="number" name="num2" id="num2" class="form__input">
<h1 class="form__heading">Operation</h1>
<ul class="form__list">
<li>
<label for="operation" class="form__radio-label">+</label>
<input type="radio" name="operation" value="+" class="form__radio">
</li>
<li>
<label for="operation" class="form__radio-label">-</label>
<input type="radio" name="operation" value="-" class="form__radio">
</li>
<li>
<label for="operation" class="form__radio-label">*</label>
<input type="radio" name="operation" value="*" class="form__radio">
</li>
<li>
<label for="operation" class="form__radio-label">/</label>
<input type="radio" name="operation" value="/" class="form__radio">
</li>
</ul>
<cainput type="submit" value="submit" class="form__submit">
</form>
</div>
<p class="result"><?php echo calculate()?></p>
</body>
</html>