-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
60 lines (57 loc) · 2 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
<html>
<head>
<title>
Kalkulator Sederhana
</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php
if (isset($_POST['hitung'])) {
$bil1 = $_POST['bil1'];
$bil2 = $_POST['bil2'];
$operasi = $_POST['operasi'];
switch ($operasi) {
case 'tambah':
$hasil = $bil1 + $bil2;
break;
case 'kurang':
$hasil = $bil1 - $bil2;
break;
case 'kali':
$hasil = $bil1 * $bil2;
break;
case 'bagi':
$hasil = $bil1 / $bil2;
break;
case 'operasi':
header('location: index.php');
break;
}
}
?>
<div class="kalkulator">
<h2 class="judul"><B>KALKULATOR</B></h2>
<form action="index.php" method="post">
<input type="number" name="bil1" class="bil" autocomplete="off" placeholder="Masukkan bilangan pertama">
<input type="number" name="bil2" class="bil" autocomplete="off" placeholder="Masukkan bilangan kedua">
<select name="operasi" class="opt" id="">
<option value="operasi">pilih operasi</option>
<option value="tambah">+</option>
<option value="kurang">-</option>
<option value="bagi">/</option>
<option value="kali">x</option>
</select>
<input type="submit" name="hitung" value="Hitung" class="tombol" id="">
</form>
<form action="">
<?php if (isset($_POST['hitung'])) { ?>
<input type="text" value="<?php echo $hasil; ?>" class="bil" name="" id="">
<input type="submit" name="operasi" value="Reset" class="reset" id="">
<?php } else { ?>
<input type="text" value="0" class="bil">
<?php } ?>
</form>
</div>
</body>
</html>