0% found this document useful (0 votes)
68 views7 pages

Codingan Aritmatika Vscode

The document contains code for several PHP programs that perform arithmetic and logical operations: 1) A program that calculates voltage (V) from current (I) and resistance (R) using Ohm's Law. 2) A program that determines the larger of two values for variables A and B. 3) A program that finds the largest of three variable values. 4) Additional programs for calculating discounts on purchases and payroll calculations for employees.

Uploaded by

triee salsabilaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views7 pages

Codingan Aritmatika Vscode

The document contains code for several PHP programs that perform arithmetic and logical operations: 1) A program that calculates voltage (V) from current (I) and resistance (R) using Ohm's Law. 2) A program that determines the larger of two values for variables A and B. 3) A program that finds the largest of three variable values. 4) Additional programs for calculating discounts on purchases and payroll calculations for employees.

Uploaded by

triee salsabilaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Codingan aritmatika vscode

<?php
if(isset($_POST['nil_i']) && isset($_POST['nil_r'])){
$i=$_POST['nil_i'];
$r=$_POST['nil_r'];

$v=$i*$r ;
}
?>

<html>
<head>
<title> fisika </title>
</head>
<body>
<h1>Perhitungan Hukum Ohm</h1>
<form action="aritmatika.php" method="POST">
<table border=1>
<tr>
<th colspan="2">Hukum Ohm</th>
</tr>
<tr>
<td>Nilai I</td>
<td><input name="nil_i" value="<?php if(isset($_POST['nil_i'])) {
echo $_POST['nil_i']; } ?>" type="text" />
</tr>
<tr>
<td>Nilai R</td>
<td><input name="nil_r" value="<?php if(isset($_POST['nil_r'])){
echo $_POST['nil_r']; } ?>" type="text" />
</tr>
<tr>
<td>Hasil</td>
<td><input name="nil_v" value="<?php if(isset($v)) { echo $v;} ?>"
type="text" />
</tr>
<tr>
<td colspan="2">
<button name="batal" type="reset" >Batal</button>
<button name="proses" type="submit" >Proses</button>
</tr>
</table>
</form>
</body>
</html>

Menampilkan harga terbesar diantara 2 variabel


<?php
if(isset($_POST['nil_a']) && isset($_POST['nil_b'])){
$a=$_POST['nil_a'];
$b=$_POST['nil_b'];

if($a>$b) {
$hasil=$a;
} else{
$hasil=$b;
};
}
?>

<html>
<head>
<title> matematika</title>
</head>
<body>
<h1>Perhitungan Harga Terbesar</h1>
<form action="logika_if.php" method="POST">
<table border=1>
<tr>
<th colspan="2">Nilai terbesar </th>
</tr>
<tr>
<td>Nilai A</td>
<td><input name="nil_a" value="<?php if(isset($_POST['nil_a'])) {
echo $_POST['nil_a']; } ?>" type="text" />
</tr>
<tr>
<td>Nilai B</td>
<td><input name="nil_b" value="<?php if(isset($_POST['nil_b'])){
echo $_POST['nil_b']; } ?>" type="text" />
</tr>
<tr>
<td>Hasil</td>
<td><input name="nil_hasil" value="<?php if(isset($hasil)) { echo
$hasil;} ?>" type="text" />
</tr>
<tr>
<td colspan="2">
<button name="batal" type="reset" >Batal</button>
<button name="proses" type="submit" >Proses</button>
</tr>
</table>
</form>
</body>
</html>

Menentukan angka terbesar 3 variabel


<?php
if(isset($_POST['angka1']) && isset($_POST['angka2']) &&
isset($_POST['angka3'])){
$angka1 = $_POST['angka1'];
$angka2 = $_POST['angka2'];
$angka3 = $_POST['angka3'];

if($angka1 > $angka2 && $angka1 > $angka3) {


$hasil = $angka1;
} elseif($angka2 > $angka1 && $angka2 > $angka3) {
$hasil = $angka2;
} else {
$hasil = $angka3;
}
}
?>

<html>
<head>
<title>Harga Terbesar</title>
</head>
<body>
<h1>Menentukan Harga Terbesar</h1>
<form action="logika_if.php" method="POST">
<table border=1>
<tr>
<th colspan="2">Angka Terbesar</th>
</tr>
<tr>
<td>ANGKA 1</td>
<td><input name="angka1" value="<?php
if(isset($_POST['angka1'])) { echo $_POST['angka1']; } ?>" type="text" />
</tr>
<tr>
<td>ANGKA 2</td>
<td><input name="angka2" value="<?php
if(isset($_POST['angka2'])){ echo $_POST['angka2']; } ?>" type="text" />
</tr>
<tr>
<td>ANGKA 3</td>
<td><input name="angka3" value="<?php
if(isset($_POST['angka3'])){ echo $_POST['angka3']; } ?>" type="text" />
</tr>
<tr>
<td>HASIL</td>
<td><input name="hasil" value="<?php if(isset($hasil)) {
echo $hasil;} ?>" type="text" />
</tr>
<tr>
<td colspan="2">
<button name="batal" type="reset" >Batal</button>
<button name="proses" type="submit" >Proses</button>
</tr>
</table>
</form>
</body>
</html>

Diskon.php
<?php
// var_dump($_POST);
$totalbelanja = isset($_POST['totalbelanja']) ? $_POST['totalbelanja'] : "";
$diskonrp = null;
$diskonpersen = null;
$hargabayar = null;

if (isset($_POST["submit"])) {
$totalbelanja = $_POST['totalbelanja'];
$diskonrp = null;
$diskonpersen = null; // Perbaikan: Menggunakan operator penugasan (=)
daripada penjumlahan (+)

if ($totalbelanja >= 5000000) {


$diskonrp = 0.02 * $totalbelanja;
$diskonpersen = 2;
} elseif ($totalbelanja >= 3000000) {
$diskonrp = 0.012 * $totalbelanja;
$diskonpersen = 1.2;
} elseif ($totalbelanja >= 1000000) {
$diskonrp = 0.005 * $totalbelanja;
$diskonpersen = 0.5;
}

$hargabayar = $totalbelanja - $diskonrp;


}

?>
<!DOCTYPE html>
<html>
<head>
<title>Mencari Diskon</title>

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


</head>

<body>
<h1>Mencari Diskon</h1>
<form action="diskon.php" method="POST">
<table border=1>

<tr>
<td>Total Belanja</td>
<td>Rp <input name="totalbelanja" value="<?php echo
$totalbelanja; ?>"></td>
</tr>
<tr>
<td>Harga Diskon</td>
<td>Rp <?php echo $diskonrp; ?> </td>
</tr>
<tr>
<td>Diskon</td>
<td><?php echo $diskonpersen; ?>% </td>
</tr>
<tr>
<td>Harga Bayar</td>
<td>Rp <?php echo $hargabayar; ?> </td>
</tr>
<tr>
<td></td>
<td><input id="tombol-submit" type="submit" name="submit"
value="Submit"/></td>
</tr>
</table>
</form>
</body>
</html>

Penggajian.php
<!DOCTYPE html>
<html>
<head>
<title>Form Penggajian</title>
</head>
<body>

<h2>Form Penggajian Karyawan</h2>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">


NIK: <input type="text" name="nik"><br><br>
Nama: <input type="text" name="nama"><br><br>
Status Nikah:
<input type="radio" name="status" value="Menikah">Menikah
<input type="radio" name="status" value="Belum Nikah">Belum Nikah
<br><br>
Jumlah Anak: <input type="number" name="jumlah_anak" min="0"><br><br>
Gaji Pokok: <input type="number" name="gaji_pokok" min="0"><br><br>
Besar Tunjangan: <input type="number" name="tunjangan" min="0"><br><br>
<input type="submit" name="submit" value="Submit">
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$nik = $_POST['nik'];
$nama = $_POST['nama'];
$status = $_POST['status'];
$jumlah_anak = $_POST['jumlah_anak'];
$gaji_pokok = $_POST['gaji_pokok'];
$tunjangan = $_POST['tunjangan'];

// Menghitung total gaji


$gaji_total = $gaji_pokok + $tunjangan;
// Proses untuk menentukan pajak berdasarkan status nikah
if ($status == "Menikah") {
// logika perhitungan pajak untuk yang sudah menikah
$pajak = 0.1 * $gaji_total;
} else {
// logika perhitungan pajak untuk yang belum menikah
$pajak = 0.05 * $gaji_total;
}

// Menghitung gaji bersih


$gaji_bersih = $gaji_total - $pajak;

// Menampilkan hasil perhitungan


echo "<h2>Hasil Perhitungan Gaji Karyawan</h2>";
echo "NIK: " . $nik . "<br>";
echo "Nama: " . $nama . "<br>";
echo "Status Nikah: " . $status . "<br>";
echo "Jumlah Anak: " . $jumlah_anak . "<br>";
echo "Gaji Pokok: " . $gaji_pokok . "<br>";
echo "Besar Tunjangan: " . $tunjangan . "<br>";
echo "Gaji Total: " . $gaji_total . "<br>";
echo "Pajak: " . $pajak . "<br>";
echo "Gaji Bersih: " . $gaji_bersih . "<br>";
}
?>

</body>
</html>

You might also like