#include <iostream>
#include <string.h>
using namespace std;
//Function NOT Return Value (Without Parameter)
void garis() {
puts("-----------------------------------------");
}
//Function NOT Return Value (With Parameter)
void ttd(char nama[20], char email[30]) {
garis();
cout<<"Nama : "<<nama<<endl;
cout<<"Email : "<<email<<endl;
}
//Function NOT Return Value (Without Parameter)
void judul(){
garis();
puts("\tProgram Latihan NESTED IF");
garis();
}
//Function NOT Return Value (Without Parameter)
void judul_bawah(){
garis();
puts("\tHasil Percabangan");
garis();
}
//Function Return Value (With Parameter)
float cek_harga(int kode, char ukuran) {
float harga = 0;
//Struktur IF
if (kode == 1) {
//Struktur IF Bersarang
if (ukuran=='S' || ukuran =='s') {
harga = 45000;
} else if (ukuran=='M' || ukuran =='m') {
harga = 55000;
} else if (ukuran=='L' || ukuran =='l') {
harga = 65000;
} else {
harga = 0;
}
} else if (kode == 2) {
//Bentuk penulisan if versi singkat
if (ukuran=='S' || ukuran == 's') harga = 75000;
else if (ukuran=='M' || ukuran == 'm') harga = 85000;
else if (ukuran=='L' || ukuran == 'l') harga = 95000;
else harga = 0;
} else {
harga = 0;
}
return harga;
}
string cek_merk(int kode) {
if (kode == 1) {
return "ERIGO";
} else if (kode == 2) {
return "UNIQLO";
} else {
return "";
}
}
float cek_subtotal(int jumbel, float harga) {
return harga * jumbel;
}
float cek_diskon(int jumbel, float subtotal) {
if (jumbel > 10) {
return 0.1 * subtotal;
} else if (jumbel > 5) {
return 0.05 * subtotal;
} else {
return 0;
}
}
float cek_total(float subtotal, float diskon) {
return subtotal - diskon;
}
int main() {
judul();
int kode, jumbel;
char ukuran;
cout<<"Kode Baju [1/2] : <INPUT>";cin>>kode;cout<<endl;
cout<<"Ukuran Baju [S/M/L] : <INPUT>";cin>>ukuran;cout<<endl;
float harga = cek_harga(kode,ukuran);
judul_bawah();
cout<<"Kode baju yang dipilih : "<<kode<<endl;
cout<<"Ukuran baju yang dipilih: "<<ukuran<<endl;
//Cek jika harga bernilai 0
if (harga == 0) {
cout<<"Harga satuan : Kode atau Ukuran Baju salah."<<endl;
} else {
cout<<"Harga satuan : "<<harga<<endl;
}
cout<<"Merk baju : "<<cek_merk(kode)<<endl;
garis();
cout<<"Jumlah Beli : <INPUT>";cin>>jumbel;cout<<endl;
//Hitung Subtotal
float subtotal = cek_subtotal(jumbel, harga);
cout<<"Subtotal : "<<subtotal<<
" ("<<jumbel<<" item)"<<endl;
//Hitung Diskon
float diskon = cek_diskon(jumbel, subtotal);
cout<<"Discount : "<<diskon<<endl;
//Hitung Total
float total = cek_total(subtotal, diskon);
cout<<"Total : "<<total<<endl;
ttd("Irsyad","irsyadpurbha.fst@uia.ac.id");
return 0;
}