#include <iostream>
#include <string.h>
using namespace std;
//Nama : Nagita Elsa
//Nim : 3420230026
void garis() {
puts("-----------------------------------------");
}
void ttd(char nama[20], char email[30]) {
garis();
cout<<"Nama : "<<nama<<endl;
cout<<"Email : "<<email<<endl;
}
void judul(){
garis();
puts("\tProgram Latihan NESTED IF");
garis();
}
void judul_bawah(){
garis();
puts("\tHasil Percabangan");
garis();
}
float cek_harga(int kode, char ukuran) {
float harga = 0;
if (kode == 1) {
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;
}
char* cek_merk(int kode) {
char* merk;
if (kode == 1) {
strcpy(merk,"ERIGO");
} else if (kode == 2) {
strcpy(merk,"UNIQLO");
} else {
strcpy(merk,"UNIQLO");
}
return merk;
}
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("Nagita Elsa","nagitaelsa39@gmail.com");
return 0;
}