Tugas 2 : Aritmatika
Kalkulator Sederhana menggunakan PHP |
Berikut adalah Script nya:
<html>
<head>
<title>"Tugas Aritmatika"</title>
</head>
<body>
<form method="post">
<?php
$a = $_POST['x'];
$b = $_POST['y'];
if(isset($_POST["jumlah"])){
$hasil = $a + $b;
}
if(isset($_POST["kurang"])){
$hasil = $a - $b;
}
if(isset($_POST["kali"])){
$hasil = $a * $b;
}
if(isset($_POST["bagi"])){
$hasil = $a / $b;
}
if(isset($_POST["mod"])){
$hasil = $a % $b;
}
?>
<table align=center style="border: 2px #006400 groove; padding:0px; background-color:#adc6d6">
<tr>
<td><input type="text" name="x" style="width:40px" value="" required></td>
<td><input type="text" name="y" style="width:40px" value="" required></td>
<td>=</td>
<td align=right><input type="text" style="width:40px" name="hasil" value="<?php echo $hasil;?>"></td>
<tr>
<td colspan=2><input type="submit" name="jumlah" style="width:60px" value="+"></td></td>
<td colspan=2><input type="submit" name="kali" style="width:60px" value="x"></td>
</tr>
<tr>
<td colspan=2><input type="submit" name="bagi" style="width:60px" value="/"></td>
<td colspan=2><input type="submit" name="kurang" style="width:60px" value="-"></td></td>
</tr>
<tr>
<td colspan=2><input type="submit" name="mod" style="width:60px" value="Mod"></td>
<td colspan=2><input type="reset" name="cancel" style="width:60px" value="Cancel"></td>
</tr>
</table>
</form>
</body>
</html>
<head>
<title>"Tugas Aritmatika"</title>
</head>
<body>
<form method="post">
<?php
$a = $_POST['x'];
$b = $_POST['y'];
if(isset($_POST["jumlah"])){
$hasil = $a + $b;
}
if(isset($_POST["kurang"])){
$hasil = $a - $b;
}
if(isset($_POST["kali"])){
$hasil = $a * $b;
}
if(isset($_POST["bagi"])){
$hasil = $a / $b;
}
if(isset($_POST["mod"])){
$hasil = $a % $b;
}
?>
<table align=center style="border: 2px #006400 groove; padding:0px; background-color:#adc6d6">
<tr>
<td><input type="text" name="x" style="width:40px" value="" required></td>
<td><input type="text" name="y" style="width:40px" value="" required></td>
<td>=</td>
<td align=right><input type="text" style="width:40px" name="hasil" value="<?php echo $hasil;?>"></td>
<tr>
<td colspan=2><input type="submit" name="jumlah" style="width:60px" value="+"></td></td>
<td colspan=2><input type="submit" name="kali" style="width:60px" value="x"></td>
</tr>
<tr>
<td colspan=2><input type="submit" name="bagi" style="width:60px" value="/"></td>
<td colspan=2><input type="submit" name="kurang" style="width:60px" value="-"></td></td>
</tr>
<tr>
<td colspan=2><input type="submit" name="mod" style="width:60px" value="Mod"></td>
<td colspan=2><input type="reset" name="cancel" style="width:60px" value="Cancel"></td>
</tr>
</table>
</form>
</body>
</html>
Komentar
Posting Komentar