Kali ini saya akan membuat kalkulator cendekia, kenapa namanya kalkulator cendekia? karena yang membuat adalah anak anak SMP Cendekia Ambon.

1. Buat file dengan nama index.php.

<!DOCTYPE html>

<html>

<head>

<title>Kalkulator Cendekia</title>

<link rel="stylesheet" type="text/css" href="style.css">

</head>

<body>

Disini Coding PHP

<div class="kalkulator">

<h2 class="judul">KALKULATOR CENDEKIA</h2>

<a class="brand" href="https://www.ydprog.com">By. Aisyah</a>

<form method="post" action="index.php">

<input type="number" required name="bil1" class="bil" autocomplete="off" placeholder="Kas Maso Angka Pertama">

<input type="number" required name="bil2" class="bil" autocomplete="off" placeholder="Kas Maso Angka Kedua">

<select class="opt" required name="operasi">

<option value="">Pilih Dolo</option>

<option value="tambah">(+)Tamba Akang</option>

<option value="kurang">(-)Kurang Akang</option>

<option value="kali">(x)Kali Akang</option>

<option value="bagi">(/)Bage Akang</option>

</select>

<input type="submit" name="hitung" value="ITONG" class="tombol">

</form>

<?php if(isset($_POST['hitung'])){ ?>

<input type="text" value="<?php echo $hasil; ?>" class="bil">

<?php }else{ ?>

<input type="text" placeholder="Dia Pung Hasil Disini" value="Dia Pung Hasil Disini" class="bil">

<?php } ?>

<br>

<br>

<a href="index.php" type="reset" class="kosong">KAS KOSONG KAKA</a>

</div>

</body>

</html>


2. Buat file dengan nama 'proses.php'

<?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;

}

}

?>

3. Buat Cssnya , simpan file css dengan nama 'style.css'

body{

background: #F2F2F2;

font-family: sans-serif;

}

 

.kalkulator{

width: 335px;

background: #4B0082;

margin: 100px auto;

padding: 10px 20px 50px 20px;

border-radius: 5px;

box-shadow: 0px 10px 20px 0px #D1D1D1;

}

 

.bil{

width: 300px;

margin: 5px;

border: none;

font-size: 16pt;

border-radius: 5px;

padding: 10px;

}

 

.opt{

font-size: 16pt;

border: none;

width: 215px;

margin: 5px;

border-radius: 5px;

padding: 10px;

}

.tombol{

background: #EC5159;

border-top: none;

border-right: none;

border-left: none;

border-radius: 5px;

padding: 10px 20px;

color: #eee;

font-size: 15pt;

border-bottom:4px solid #BF3D3D;

}


.kosong{

background: #FFFF00;

border-top: none;

border-right: none;

border-left: none;

border-radius: 5px;

padding: 5px 100px;

color: #BF3D3D;

font-size: 10pt;

border-bottom:4px solid #FFFF00;

}

 

.brand{

color: #eee;

font-size: 11pt;

float: right;

text-decoration: none;

margin: 12px;

}

 

.judul{

text-align: center;

color: #eee;

font-weight: normal;

}


Setelah itu jalankan dengan mengakses : 

localhost/nama/project . Contoh localhost/aini/kalkulator/


Catatan : Ganti pada index.php pada bagian 'Disini Coding PHP' dengan include ''proses.php".

https://www.ydprog.com/2024/01/membuat-kalkulator-sederhana-dengan-php.html

  Pendaftaran SMP Cendekia Ambon Tahun Pelajaran 2024-2025






DAFTAR SEKARANG