-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrade-sum.php
64 lines (56 loc) · 1010 Bytes
/
grade-sum.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
<!DOCTYPE html>
<html>
<head>
<style>
html {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
font-size: 1.5rem;
}
form {
display: flex;
flex-direction: column;
align-items: center;
}
form input {
text-align: center;
width: 15vw;
height: 3vw;
}
</style>
</head>
<body>
<h2>average grade:</h2>
<form action="index.php" method="get">
<input type="text" name="num" id="">
<input type="submit" value="OK">
</form>
<br>
<?php
if(isset($_GET['num']) and !empty($_GET['num'])){
$values = $_GET['num'];
$valArr = explode(",", $values);
$sum = 0;
$i = 0;
if(is_array($valArr)){
foreach($valArr as $item){
if(is_numeric($item) and $item >= 1 and $item <= 6){
$sum += $item;
$i++;
}
}
}
if($i > 0){
echo "Result is: " . round($sum / $i, 2);
}else{
echo "Lack of grades...";
}
}else{
echo "Insert values, please !";
}
?>
</body>
</html>