Jumat, 14 Desember 2012

Contoh Switch Case dan IF Else pd Borland C++


#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <string.h>

main()
{
char  pet[20],cust[20],my[6],kode,kmr[10];
long  harga,jum,diskon,bayar,uang,kembalian;
int in,out,sewa;

cout<<"Penginapan PANDA,lnn\n";
cout<<"======================\n\n";
cout<<"Input Nama Petugas  : ";gets(pet);
cout<<"Input Nama Customer : ";gets(cust);
cout<<"Input Tanggal Check in : ";cin>>in;cin>>my;
cout<<"======================\n\n";

clrscr();
printf("    DAFTAR KAMAR YANG TERSEDIA\n\n");
printf("=====================================\n");
printf("| Kode Kamar | Nama Kamar |  Harga  |\n");
printf("=====================================\n");
printf("|      L     |   Lily          | 250.000 |\n");
printf("|      M    |   Mawar    |   75.000 |\n");
printf("|      S     |   Sakura    | 150.000 |\n");
printf("====================================\n");

cout<<"\nPilih Kode Kamar [L/M/S] : ";cin>>kode;
cout<<"Lama Sewa : ";cin>>sewa;
cout<<endl;

switch(kode)
{
case 'L':
case 'l':
strcpy(kmr,"Lily");
harga=250000;
jum=sewa*harga;
break;
case 'M':
case 'm':
strcpy(kmr,"Mawar");
harga=75000;
jum=sewa*harga;
break;
case 'S':
case 's':
strcpy(kmr,"Sakura");
harga=150000;
jum=sewa*harga;
break;
}

if(sewa>5)
{
printf("\n>>> Selamat Anda Dapat Diskon 10% <<<\n\n");
diskon=(jum*0.1);
bayar=jum-diskon;
}
else if(sewa>3)
{
printf("\n>>> Selamat Anda Dapat Diskon 5% <<<\n\n");
diskon=(jum*0.05);
bayar=jum-diskon;
}
else
{
printf("\n>>> Maaf Anda Tidak Dapat Diskon <<<\n\n");
diskon=0;
bayar=jum;
}

//clrscr();
printf("\n\t\tBUKTI PEMESANAN KAMAR");
printf("\n\t\tPenginapan PANDA,Inn");
printf("\n-----------------------------------------------------\n\n");

printf(" Nama Petugas  : %s          Check In  : %d%s",pet,in,my);
out=in+sewa;
printf(" \n Nama Customer : %s          Check Out : %d%s",cust,out,my);
cout<<"\n\n=====================================================\n";
cout<<"\n Nama Kamar Yang Dipesan \t: "<<kmr;
cout<<"\n Harga Sewa Kamar \t\t: Rp. "<<harga;
printf("\n Lama Sewa Kamar \t\t: %d   (Hari)",sewa);
cout<<"\n\n=====================================================\n";
cout<<"\n\t Jumlah Bayar \t\t: Rp. "<<jum;
cout<<"\n\t Diskon \t\t: Rp. "<<diskon;
cout<<"\n\n=====================================================\n";

cout<<"\n\t Total Bayar \t\t: Rp. "<<bayar;
cout<<"\n\t Uang Bayar \t\t: Rp. ";cin>>uang;
kembalian=uang-bayar;
cout<<"\t Uang Kembali \t\t: Rp. "<<kembalian;
printf("\n\n-----------------------------------------------------\n\n");

printf("\t*** Terima Kasih Atas Kunjungannya ***");
getch();
}

Tidak ada komentar:

Poskan Komentar