This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc.php
67 lines (59 loc) · 1.82 KB
/
calc.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
<?php
session_start();
$result = 0;
if(isset($_POST['add']))
$result = $_POST['num1'] + $_POST['num2'];
elseif(isset($_POST['subtract']))
$result = $_POST['num1'] - $_POST['num2'];
elseif(isset($_POST['multiply']))
$result = $_POST['num1'] * $_POST['num2'];
elseif(isset($_POST['divide']))
$result = $_POST['num1'] / $_POST['num2'];
elseif(isset($_POST['exp']))
$result = pow($_POST['num1'],$_POST['num2']);
if(isset($_SESSION['result']))
if(isset($_POST['memplus']))
$result = $_SESSION['result'] + $_POST['num1'];
elseif(isset($_POST['memminus']))
$result = $_SESSION['result'] - $_POST['num1'];
elseif(isset($_POST['reset']))
session_unset();
$_SESSION['result'] = $result;
?>
<html>
<head>
<title>
ADVWEB1 Exercise #6
</title>
</head>
<body>
<p>
<b>Calculator</b><br>
<form action="calc.php" method="post">
<input type="number" name="num1"><br>
<input type="number" name="num2"><br><br>
<input type="submit" name="add" value="+">
<input type="submit" name="subtract" value="-">
<input type="submit" name="multiply" value="*">
<input type="submit" name="divide" value="/"><br>
<input type="submit" name="memplus" value="M+">
<input type="submit" name="memminus" value="M-">
<input type="submit" name="reset" value="MC"><br>
<input type="submit" name="exp" value="xⁿ">
</form>
</p>
<p>
<b>
Result: <?php echo $result; ?><br>
Memory: <?php echo $_SESSION['result']; ?>
</b>
</p>
<br>
<p>
How to use:<br><br>
Input two numbers and press the appropriate mathematical operation.<br>
For exponents, enter the base number on the first input and the exponent on the second input.<br>
Use the first input also for Memory+ and Memory- operations.
</p>
</body>
</html>