Contoh Switch di C++

#include<iostream.h>
#include<conio.h>
main()
{
int kode,jmlunit;
float harga,diskon,sbldiskon,hargatotal,uterima,kembalian;
cout<<"Jumlah Unit : ";
cin>>jmlunit;
cout<<"Harga : ";
cin>>harga;
sbldiskon=jmlunit*harga;
cout<<"Total sebelum diskon : "<<sbldiskon<<endl;
if ((sbldiskon>25000)&&(sbldiskon<=50000))
kode=1;
else if ((sbldiskon>50000)&&(sbldiskon<=75000))
kode=2;
else if ((sbldiskon>75000) &&(sbldiskon<=100000))
{
kode=3;
}
else if (sbldiskon>100000)
{
kode=4;
}

switch(kode)
{
case 1:
diskon=sbldiskon*0.25;
break;
case 2:
diskon=sbldiskon*0.3;
break;
case 3:
diskon=sbldiskon*0.5;
break;
case 4:
diskon=sbldiskon*0.75;
break;
default :
diskon=0;
}

cout<<"Kode : "<<kode<<endl;
cout<<"Diskon : "<<diskon<<endl;
hargatotal=sbldiskon-diskon;
cout<<"Harga Total : "<<hargatotal<<endl;
cout<<"Uang diterima : ";
cin>>uterima;
kembalian=uterima-hargatotal;
cout<<"Kembalian : "<<kembalian<<endl;
getch();
}

Hasil
modul3.jpg

Posted on Desember 18, 2007, in C++ and tagged , , , , . Bookmark the permalink. Tinggalkan komentar.

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: