Random News

Fungsi IF Pada Cpp


//*Pernyataan IF.cpp*//
#include
#include
#include

main()
{
            double tot_beli, potongan=0,jum_bayar=0;
            clrscr();
           
            cout<<”Total Pembelian Rp. “;cin>>tot_beli;
           
            if (tot_beli >= 50000)
                        potongan = 0.2 * tot_beli;
            cout<<”Maka Besarnya Potongan Rp.
“<
            jum_bayar = tot_beli – potongan;
            cout<<”Jumlah Yang Harus Dibayar Rp.
“,jum_bayar;
            getch();
}
    
//*Pernyataan IF – ELSE*//
#include
#include
#include

main()
{
            double tot_beli, potongan=0,jum_bayar=0;
            clrscr();
           
            cout<<”Total Pembelian Rp. “;cin>>tot_beli;
           
            if (tot_beli >= 50000)
                        potongan = 0.2 * tot_beli;
            else
                        potongan = 0.05 * tot_beli;

            cout<<”Maka Besarnya Potongan Rp. “<
           
            jum_bayar = tot_beli – potongan;

            cout<<”Jumlah Yang Harus Dibayar Rp.
“,jum_bayar;
            getch();
}



//*Pernyataan IF – ELSE Majemuk.cpp*//
#include
#include
#include

main()
{
            float pendapatan, jasa=0, komisi=0, total=0;
            clrscr();
           
            cout<<”Pendapatan Hari Ini Rp.
“;cin>>pendapaatan;
           
            if (pendapatan >= 0 && pendapatan <=200000)
            {
                        jasa=10000;
                        komisi=0.1 * pendapatan;
            }
            else if(pendapatan<=500000)
                        {
                                    jasa=20000;
                                    komisi=0.15*pendapatan;
                        }
            else
            {
                        jasa=30000;
                        komisi=0.2*pendapatan;
            }
           
            total = komisi + jasa;

            cout<<”Uang Jasa                    Rp. “<
            cout<<”Uang Komisi                Rp. “<
            cout<<”============================”<
            cout<<”Hasil Total                   Rp.
“<

            getch();
)


//*Pernyataan NESTED – IF.cpp*//
#include
#include
#include

main()
{
            float pendapatan, jasa=0, komisi=0, total=0;
            clrscr();
            cout<<”Pendapatan Hari Ini Rp. “;cin>>pendapaatan;
            if (pendapatan >= 0 && pendapatan <=200000)
            {
                        jasa=10000;
                        komisi=0.1 * pendapatan;
            }
            else
            {
                        if(pendapatan<=500000)
                        {
                                    jasa=20000;
                                    komisi=0.15*pendapatan;
                        }
                        else
                        {
                                    jasa=30000;
                                    komisi=0.2*pendapatan;
                        }
            }
            total = komisi + jasa;
            cout<<”Uang Jasa                    Rp. “<
            cout<<”Uang Komisi                Rp. “<
            cout<<”============================”<
            cout<<”Hasil Total                   Rp.
“<
             getch();
)
Share on Google Plus

About Unknown

    Blogger Comment
    Facebook Comment

0 opmerkings: