Contoh 11.1 Algoritma

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> #include <iomanip> #include <string> using namespace std; int main() { int kode, jumlah; char ukuran; int harga; string merk; double subtotal, discount, total; cout << "---------------------------------------------\n"; cout << " Program Latihan NESTED IF\n"; cout << "---------------------------------------------\n"; cout << "Kode Baju [1/2] : <input>\n"; cin >> kode; cout << "Ukuran Baju [S/M/L] : <input>\n"; cin >> ukuran; cout << "---------------------------------------------\n"; cout << "Hasil Percabangan\n"; cout << "---------------------------------------------\n"; if (kode == 1) { merk = "GUCCI"; if (ukuran == 'S' || ukuran == 's') harga = 120000; else if (ukuran == 'M' || ukuran == 'm') harga = 130000; else if (ukuran == 'L' || ukuran == 'l') harga = 140000; else harga = 0; } else if (kode == 2) { merk = "UNIQLO"; if (ukuran == 'S' || ukuran == 's') harga = 85000; else if (ukuran == 'M' || ukuran == 'm') harga = 90000; else if (ukuran == 'L' || ukuran == 'l') harga = 95000; else harga = 0; } else { merk = "Tidak diketahui"; harga = 0; } cout << "Kode baju yang dipilih : " << kode << endl; cout << "Ukuran baju yang dipilih: " << ukuran << endl; cout << "Harga satuan \t: " << harga << endl; cout << "Merk baju \t: " << merk << endl; cout << "---------------------------------------------\n"; cout << "Jumlah Beli \t: <input> "; cin >> jumlah; subtotal = harga * jumlah; discount = subtotal * 0.05; // diskon 5% total = subtotal - discount; cout << fixed << setprecision(0); cout << "\nSubtotal \t: " << subtotal << " (" << jumlah << " item)" << endl; cout << "Discount \t: " << discount << endl; cout << "Total \t: " << total << endl; cout << "---------------------------------------------\n"; cout << "Nama : Muhammad Rifqi Hidayat\n"; cout << "Email : rifqihidayat266@gmail.com\n"; cout << "---------------------------------------------\n"; return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines