Friday, October 22, 2010

Perhitungan dalam persen C++ (2)

Contoh perhitungan persen :

//======================================//

#include <iostream>

int main()
{
        using namespace std;
        char code;
        double  hargaA=70000, hargaB=50000, beli, bayar, jml, disc, total_disc, total;
        const int ppn=10;
        cout << "\n";
        cout << "--------------------------------------------------------\n";
        cout << "\tBUKU YANG DI BELI\n\n";
        cout << "Masukan Kode Buku : ";
        cin >> code;
        if((code=='A') || code=='a')
        {
                cout << "Merk Buku         : GRAMEDIA\n";
                cout << "Harga             : " << hargaA <<endl;
                cout << "Beli              : ";
                cin >> beli;
                jml = hargaA * beli;
                jml = hargaA * beli;
                cout << "Ditambah PPN      : 10%\n";
                total = jml / ppn + jml;
                if(beli >=8) {
                        disc = jml * 5 / 100;
                        total_disc = total - disc;
                        cout << "Discount          : 5%\n";
                        cout <<"\nTotal Harga yg harus dibayar + Disc + PPN = Rp. "<<total_disc<<endl;
                        cout << "--------------------------------------------------------\n\n";
                        return 0;
                } else if(beli >=5) {
                        disc = jml * 2 / 100;
                        total_disc = total - disc;
                        cout << "Discount          : 2%\n";
                        cout <<"\nTotal Harga yg harus dibayar + Disc + PPN = Rp. "<<total_disc<<endl;
                        cout << "--------------------------------------------------------\n\n";
                        return 0;
                } else if(beli <=2) {
                        disc = jml * 1 / 100;
                        total_disc = total - disc;
                        cout << "Discount          : 1%\n";
                        cout <<"\nTotal Harga yg harus dibayar + Disc + PPN = Rp. "<<total_disc<<endl;
                        cout << "--------------------------------------------------------\n\n";
                        return 0;
                }
                cout <<"\nTotal Harga yg harus dibayar + PPN = Rp. "<<total<<endl;
        } else
        if((code=='B') || code=='b')
        {
                cout << "Merk Buku         : ELEXMEDIA\n";
                cout << "Harga             : " << hargaB <<endl;
                cout << "Beli              : ";
                cin >> beli;
                jml = hargaB * beli;
                cout << "Ditambah PPN      : 10%\n";
                total = jml / ppn + jml;
                if(beli >=5) {
                        disc = jml * 5 / 100;
                        total_disc = total - disc;
                        cout << "Discount          : 5%\n";
                        cout <<"\nTotal Harga yg harus dibayar + Disc + PPN = Rp. "<<total_disc<<endl;
                        cout << "--------------------------------------------------------\n\n";
                        return 0;
                } else if(beli >=3) {
                        disc = jml * 3 / 100;
                        total_disc = total - disc;
                        cout << "Discount          : 3%\n";
                        cout <<"\nTotal Harga yg harus dibayar + Disc + PPN = Rp. "<<total_disc<<endl;
                        cout << "--------------------------------------------------------\n\n";
                        return 0;
                } else if(beli <=2) {
                        disc = jml * 1 / 100;
                        total_disc = total - disc;
                        cout << "Discount          : 1%\n";
                        cout <<"\nTotal Harga yg harus dibayar + Disc + PPN = Rp. "<<total_disc<<endl;
                        cout << "--------------------------------------------------------\n\n";
                        return 0;
                }
                cout <<"\nTotal Harga yg harus dibayar + PPN = Rp. "<<total<<endl;
        }
        cout << "--------------------------------------------------------\n\n";
        return 0;
}

//==============================================//


Hasil output nya akan seperti ini :



                                                   ##### END #####

0 comments: