Minggu, 30 Oktober 2011

KALKULATOR SEDERHANA

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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"> 
 
<head profile="http://gmpg.org/xfn/11"> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
 
<title>Aplikasi Kalkulator Sederhana</title>
 
<style>
body{ background:#eee; font:12px Arial; }
h1{ color:#dd3380 }
form{ border:1px solid; width:40%; margin:10px; padding:15px 10px; 
-moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; }
#rst{ color:#dd3380; font-size:16px; }
</style>
 
<body>
 <center>
 <h1>Aplikasi Kalkulator Sederhana</h1>
 <form action="" method="post">
 bil 1 <input type="text" name="bil1" /><br />
 <select name="opr">
 <option value="add">+</option>
 <option value="min">-</option>
 <option value="mul">*</option>
 <option value="div">/</option>
 </select><br />
 bil 2 <input type="text" name="bil2" /><br />
 <input type="submit" value="hitung" name="get" />
 </form>
 
 <div id="rst">
 <?php 
 if(isset($_POST['get'])){
    if($_POST['opr']=='add') $r = $_POST['bil1'] + $_POST['bil2'];
    else if($_POST['opr']=='min') $r = $_POST['bil1'] - $_POST['bil2'];
    else if($_POST['opr']=='mul') $r = $_POST['bil1'] * $_POST['bil2'];
    else if($_POST['opr']=='div') $r = $_POST['bil1'] / $_POST['bil2'];
 
    echo 'Hasil dari '.$_POST['bil1'].' '.$_POST['opr'].' '.$_POST['bil2'].' adalah '.$r;  
 }
 ?>
 </div>
 </center>
</body>
</html>

Tidak ada komentar:

Posting Komentar