SELAMAT DATANG DI BLOG HUSNY ARIFUDDIN

Sabtu, 14 April 2012

C++ Program Switch - Case

#include <iostream.h>
#include <conio.h>
#include <math.h>
main()
{
int pil,s,L,kel,p,l,r,a,t;
char yt;
atas:
clrscr();
cout<<"\n<<<PROGRAM MENGHITUNG BANGUN DATAR>>>\n";
cout<<"---------------------------------------\n";
cout<<"\t1. Bujursangkar\n";
cout<<"\t2. Persegi Panjang\n";
cout<<"\t3. Lingkaran\n";
cout<<"\t4. Segitiga Siku-Siku\n";
cout<<"\t5. Selesai\n";
cout<<"---------------------------------------\n";
cout<<"Pilih Nomor (1-5) ? ";
cin>>pil;
switch(pil)
{
case 1:
cout<<"\nMasukkan sisi Bujursangkar = ";
cin>>s;
L=s*s;
kel=s*4;
cout<<"\nLuas Bujursangkar     = "<<L;
cout<<"\nKeliling Bujursangkar = "<<kel;
break;
case 2:
cout<<"\nMasukkan Panjang = ";cin>>p;
cout<<"\nMasukkan Lebar   = ";cin>>l;
L=p*l;
kel=(p*2)+(l*2);
cout<<"\nLuas Persegi Panjang     = "<<L;
cout<<"\nKeliling Persegi Panjang = "<<kel;
break;
case 3:
cout<<"\nMasukkan jari-jari = ";cin>>r;
L=r*r*3.14;
kel=r*2*3.14;
cout<<"\nLuas lingkaran     = "<<L;
cout<<"\nKeliling lingkaran = "<<kel;
break;
case 4:
cout<<"\nMasukkan alas segitiga   = ";cin>>a;
cout<<"\nMasukkan Tinggi segitiga = ";cin>>t;
L=a*t*0.5;
kel=a+t+sqrt((a*a) + (t*t));
cout<<"\nLuas segitiga     = "<<L;
cout<<"\nKeliling segitiga = "<<kel;
break;
default:
cout<<"\nAnda tidak memilih salah satu bangun datar";
}
cout<<"\n\nAnda akan melakukan perhitungan ulang ? ";cin>>yt;
if(yt=='y'||yt=='Y')
goto atas;
else
cout<<"\nTERIMA KASIH";
getch();
return 0;
}


Tidak ada komentar:

Posting Komentar