<?php
// Fungsi untuk menghitung total harga setelah diskon dan pajak
function hitungTotal( $harga , $diskon , $pajak ) {
$hargaSetelahDiskon = $harga - ( $harga * ( $diskon / 100 ) ) ; // Menghitung diskon
$hargaDenganPajak = $hargaSetelahDiskon + ( $hargaSetelahDiskon * ( $pajak / 100 ) ) ; // Menghitung pajak
return $hargaDenganPajak ; // Mengembalikan total harga
}
// Meminta input jumlah barang dari pengguna
echo "Masukkan jumlah barang: \n " ;
$jumlahBarang = ( int
) trim ( fgets ( STDIN
) ) ; // Membaca input jumlah barang
// Inisialisasi array untuk menyimpan data harga, diskon, dan pajak
$hargaArray = [ ] ;
$diskonArray = [ ] ;
$pajakArray = [ ] ;
// Loop untuk meminta input harga, diskon, dan pajak setiap barang
for ( $i = 0 ; $i < $jumlahBarang ; $i ++ ) {
echo "Masukkan harga barang ke-" . ( $i + 1 ) . ": \n " ;
$hargaArray [ $i ] = ( float
) trim ( fgets ( STDIN
) ) ; // Membaca harga barang
echo "Masukkan diskon barang ke-" . ( $i + 1 ) . " (%): \n " ;
$diskonArray [ $i ] = ( float
) trim ( fgets ( STDIN
) ) ; // Membaca diskon barang
echo "Masukkan pajak barang ke-" . ( $i + 1 ) . " (%): \n " ;
$pajakArray [ $i ] = ( float
) trim ( fgets ( STDIN
) ) ; // Membaca pajak barang }
// Perulangan untuk menghitung total harga setiap barang
echo "\n Hasil Perhitungan Total Harga Barang:\n " ;
for ( $i = 0 ; $i < $jumlahBarang ; $i ++ ) {
$totalHarga = hitungTotal( $hargaArray [ $i ] , $diskonArray [ $i ] , $pajakArray [ $i ] ) ;
echo "Barang ke-" . ( $i + 1 ) . ": IDR " . number_format ( $totalHarga , 2 , ',' , '.' ) . "\n " ; }
?>
PD9waHAKLy8gRnVuZ3NpIHVudHVrIG1lbmdoaXR1bmcgdG90YWwgaGFyZ2Egc2V0ZWxhaCBkaXNrb24gZGFuIHBhamFrCmZ1bmN0aW9uIGhpdHVuZ1RvdGFsKCRoYXJnYSwgJGRpc2t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