Quick actions

cmd+k|ctrl+k

Navigation

Languages

Algoritma 11.1

Snippet info

Language

Cpp

Visibility

public

Author

laodeiyan21

Created

2026-01-05T02:22:05.126546Z

Updated

2026-01-05T02:22:05.126546Z

#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], char nim[20]) {
    garis();
    cout << "Nama  : " << nama << endl;
    cout << "Email : " << email << endl;
    cout << "Nim   : " << nim << endl;
}

// --- FUNCTION NOT RETURN VALUE (Without Parameter) ---
void judul() {
    garis();
    puts("\tProgram Latihan NESTED IF");
    garis();
}

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;
}

// --- MAIN FUNCTION ---
int main() {
    judul();
    int kode, jumbel;
    char ukuran;

    cout << "Kode Baju [1/2]    : "; cin >> kode;
    printf("%i\n",kode);
    cout << "Ukuran Baju [S/M/L]: "; cin >> ukuran;
    printf("%c",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              : "; cin >> jumbel;
    printf("%i",jumbel);
    cout << endl;

    // Hitung Subtotal
    float subtotal = cek_subtotal(jumbel, harga);
    cout << "Subtotal                 : " << subtotal;
    cout << " (" << 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("la ode ian", "[email protected]", "3420210002");

    return 0;
}
INFO