langsung saja tanpa basa basi berikut adalah koding kalkulator tulislah koding berikut lalu save dengan format .php dan simpan di htdocs kalian.
ini koding untuk inputan perhitungan kalkulator save dengan nama kalkulator.php
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body,td,th {
color: #000;
}
.putih{ color:white;}
</style>
</head>
<body>
<form action="hasil.php" method="post">
<div align="center">
<p> </p>
<table width="381" height="140" border="1">
<tr>
<td colspan="2" bgcolor="#333333"><div align="center" class="pink"><strong>Program Kalkulator Sederhana</strong></div></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"><strong>Nilai Pertama</strong></td>
<td bgcolor="#CCCCCC"> <input name="nilai1" type="text" /></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"><strong>Operator</strong></td>
<td bgcolor="#CCCCCC"> <select name="operator">
<option>Penjumlahan</option>
<option>Pengurangan</option>
<option>Perkalian</option>
<option>Pembagian</option>
</select></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"><strong>Nilai Kedua</strong></td>
<td bgcolor="#CCCCCC"> <input name="nilai2" type="text" /></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"> </td>
<td bgcolor="#CCCCCC"> <input name="" type="submit" value="Hitung" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
dan ini adalah koding untuk hasil kalkulator save dengan nama hasil.php
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$nilai1 = $_POST['nilai1'];
$nilai2 = $_POST['nilai2'];
$operator = $_POST['operator'];
if ($operator == "Penjumlahan")
{
$hasil = $nilai1 + $nilai2;
$tanda = "+";
}
else if ($operator == "Pengurangan")
{
$hasil = $nilai1 - $nilai2;
$tanda = "-";
}
else if ($operator == "Perkalian")
{
$hasil = $nilai1 * $nilai2;
$tanda = "*";
}
else if ($operator == "Pembagian")
{
$hasil = $nilai1 / $nilai2;
$tanda = "/";
}
?>
<div align="center">
<table width="411" height="156" border="1">
<tr>
<td colspan="2"><div align="center">Hasil Perhitungan</div></td>
</tr>
<tr>
<td>Nilai Pertama</td>
<td> <?php echo "$nilai1"; ?></td>
</tr>
<tr>
<td>Operator</td>
<td> <?php echo "$tanda"; ?></td>
</tr>
<tr>
<td>Nilai kedua</td>
<td> <?php echo "$nilai2"; ?></td>
</tr>
<tr>
<td>Hasil</td>
<td> <?php echo "$hasil"; ?></td>
</tr>
</table>
</div>
</body>
</html>
maka hasilnya akan seperti ini
0 komentar:
Posting Komentar