Contoh Program C++ Switch Case

#include <constream.h>
void main()
{
clrscr();
int menu;
int a, t;
int p, l;
int s;
float ls, lp, le;
do
{
clrscr();
cout<<“Daftar Menu”;
cout<<“\n 1. Luas Segitiga”;
cout<<“\n 2. Luas Persegi Panjang”;
cout<<“\n 3. Luas Persegi Empat”;
cout<<“\n Masukan Menu Pilihan (0 Selesai) : “; cin>>menu;

switch(menu)
{
case 1 :
{
cout<<“\n Masukan Alas : “; cin>>a;
cout<<“\n Masukan Tinggi : “; cin>>t;
ls=a*t/2;
cout<<“\n Luas Segitiga : “<<ls;
}
break;
case 2 :
{
cout<<“\n Masukan Panjang : “; cin>>p;
cout<<“\n Masukan Lebar : “; cin>>l;
lp=p*l;
cout<<“\n Luas Persegi Panjang : “<<lp;
}
break;
case 3 :
{
cout<<“\n Masukan Sisi Persegi : “; cin>>s;
le=s*s;
cout<<“\n Luas Persegi Panjang : “<<le;
}
break;
case 0 :
{
cout<<“Selesai”;
break;
}
default:
cout<<“Pilihan Anda salah”;
}
getch();
}
while(menu!=0);
}

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