forked from kokonior/PHP-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kokonior#608 from adityayafi/patch-1
Create kalkulatorr.php
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Membuat Kalkulator Sederhana Dengan PHP | www.malasngoding.com</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; | ||
} | ||
} | ||
?> | ||
<div class="kalkulator"> | ||
<h2 class="judul">KALKULATOR</h2> | ||
<a class="brand" href="https://www.malasngoding.com">www.malasngoding.com</a> | ||
<form method="post" action="index.php"> | ||
<input type="text" name="bil1" class="bil" autocomplete="off" placeholder="Masukkan Bilangan Pertama"> | ||
<input type="text" name="bil2" class="bil" autocomplete="off" placeholder="Masukkan Bilangan Kedua"> | ||
<select class="opt" name="operasi"> | ||
<option value="tambah">+</option> | ||
<option value="kurang">-</option> | ||
<option value="kali">x</option> | ||
<option value="bagi">/</option> | ||
</select> | ||
<input type="submit" name="hitung" value="Hitung" class="tombol"> | ||
</form> | ||
<?php if(isset($_POST['hitung'])){ ?> | ||
<input type="text" value="<?php echo $hasil; ?>" class="bil"> | ||
<?php }else{ ?> | ||
<input type="text" value="0" class="bil"> | ||
<?php } ?> | ||
</div> | ||
</body> | ||
</html> |