Quick actions

cmd+k|ctrl+k

Navigation

Languages

Contoh 11.1 Algoritma

Snippet info

Language

Cpp

Visibility

public

Author

muhammad-rifqi

Created

2025-12-20T04:42:53.995168Z

Updated

2025-12-20T04:42:53.995168Z

#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  : [email protected]\n";
    cout << "---------------------------------------------\n";

    return 0;
}
INFO