Contoh IF pada C++

New Page 1

//*Pernyataan IF.cpp*//

#include<stdio.h>

#include<conio.h>

#include<iostream.h>

 

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.
“<<potongan<<endl;

            jum_bayar = tot_beli – potongan;

            cout<<”Jumlah Yang Harus Dibayar Rp.
“,jum_bayar;

            getch();

}

    

//*Pernyataan IF – ELSE*//

#include<stdio.h>

#include<conio.h>

#include<iostream.h>

 

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. “<<potongan<<endl;

           

            jum_bayar = tot_beli – potongan;

 

            cout<<”Jumlah Yang Harus Dibayar Rp.
“,jum_bayar;

            getch();

}

 

 

 

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

#include<stdio.h>

#include<conio.h>

#include<iostream.h>

 

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. “<<jasa<<endl;

            cout<<”Uang Komisi                Rp. “<<komisi<<endl;

            cout<<”============================”<<endl;

            cout<<”Hasil Total                   Rp.
“<<total<<endl;

 

            getch();

)

 

 

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

#include<stdio.h>

#include<conio.h>

#include<iostream.h>

 

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. “<<jasa<<endl;

            cout<<”Uang Komisi                Rp. “<<komisi<<endl;

            cout<<”============================”<<endl;

            cout<<”Hasil Total                   Rp.
“<<total<<endl;

             getch();

)

           

2 Tanggapan

  1. mksh bnyaaaaaaaaaaaaaaaaaaak………..

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: