-
Notifications
You must be signed in to change notification settings - Fork 192
/
calculator.php
52 lines (46 loc) · 1.52 KB
/
calculator.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
<head>
<meta charset="utf-8">
<title>Calculator</title>
</head>
<body>
<h2>Calculator</h2>
<form method="get" attribute="post" action="calculator.php">
<p>First Value:<br />
<input type="number" id="first" name="first">
</p>
<p>Second Value:<br />
<input type="number" id="second" name="second">
</p>
<input type="radio" name="group1" id="add" value="add" checked="true">
+
<input type="radio" name="group1" id="subtract" value="subtract">
-
<input type="radio" name="group1" id="times" value="times">
x
<input type="radio" name="group1" id="divide" value="divide">
: <br> <br>
<button type="submit" name="answer" id="answer" value="answer">Calculate</button>
</form>
</body>
</html>
<?php
if (isset($_GET['answer'])) {
switch ($_GET['group1']) {
case "add":
echo "Result :" . ($_GET['first'] + $_GET['second']);
break;
case "subtract":
echo "Result :" . ($_GET['first'] - $_GET['second']);
break;
case "times":
echo "Result :" . ($_GET['first'] * $_GET['second']);
break;
case "divide":
echo "Result :" . ($_GET['first'] / $_GET['second']);
break;
default:
echo "";
break;
}
}
?>