Nomor 5 SWITCH-CASE

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.5 kB
6
Indexable
Never
#include<iostream>
using namespace std;

int main(){
    int golongan, jamKerja, gajiTetap, gajiJam, jamLembur, gajiJam_total, gajiLembur, gajiTotal;

    cout << "Masukkan golongan : ";
    cin >> golongan;

    switch(golongan){
        case 1 :
            gajiTetap = 1500000;
            gajiJam = 10000;
            break;
        case 2 :
            gajiTetap = 1750000;
            gajiJam = 12500;
        case 3 :
            gajiTetap = 2000000;
            gajiJam = 15000;
        case 4 :
            gajiTetap = 2500000;
            gajiJam = 17500;
        case 5 :
            gajiTetap = 3000000;
            gajiJam = 20000;
        default :
            cout << "Golongan tidak diketahui" << endl;
            main();
            return 0;
    }

    cout << "Masukkan jumlah jam kerja : ";
    cin >> jamKerja;

    if (jamKerja > 120) {
        jamLembur = jamKerja - 120;
    } else {
        jamLembur = 0;
    }

    gajiLembur = 1.5 * jamLembur * gajiJam;
    gajiJam_total = jamKerja * gajiJam;
    gajiTotal = gajiTetap + (jamKerja * gajiJam) + gajiLembur;

    cout << "Jam kerja        =   " << jamKerja << endl;
    cout << "Jam lembur       =   " << jamLembur << endl;
    cout << "Gaji per jam     = Rp" << gajiJam << endl;
    cout << "Gaji tetap       = Rp" << gajiTetap << endl;
    cout << "Ttl Gaji per jam = Rp" << gajiJam_total << endl;
    cout << "Gaji lembur      = Rp" << gajiLembur << endl;
    cout << "Gaji total       = Rp" << gajiTotal << endl;
}