Sunday, 9 March 2025

Contoh Program if bersarang (Diskon Buku)

 #include <iostream>

#include <string.h>

using namespace std;

int main( ){

    char kodeDiskon,namaBuku[30];

    long harga=0;

    int kode;

    cout<<"Kode Buku : ";cin>>kode;

    cout<<"Kode Diskon : ";cin>>kodeDiskon;

    if (kode == 1)    

{

        strcpy(namaBuku," Buku Sekolah ");

        if (kodeDiskon=='S' || kodeDiskon =='s')

{

           harga=45000;

        } else {

           cout<< " Kode Diskon Salah "<<endl;

        }

    } else if (kode==2) {

        strcpy(namaBuku," Komik ");

        if (kodeDiskon=='S' || kodeDiskon=='s'){

           harga=65000;

        } else {

           cout<< " Kode Diskon Salah "<<endl;

        }

    } 

else if (kode==3) {

        strcpy(namaBuku," Pengetahun Umum ");

        if (kodeDiskon=='S' || kodeDiskon=='s'){

           harga=75000;

        } else {

           cout<< " Kode Diskon Salah "<<endl;

        }

}else {

        cout<<"Salah Kode Buku"<<endl;

    }

    cout<<"----------------------"<<endl;

    cout<<"Judul Buku : "<<namaBuku<<endl;

    cout<<"Harga Buku : "<<harga<<endl;

    return 0;

}

No comments:

Post a Comment