Program Pernyataan switch-case |
/*filename = Program Pernyataan switch-case */
/*Oleh : fk_seven */
/*Date : 14 Agustus 2011 */
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
main()
{
atas :
clrscr();
char lagi;
char kode, barang[30];
int harga, jml, total;
gotoxy(17,3);cout<<"Latihan Switch - Case";
gotoxy(10,4);cout<<" ================================";
gotoxy(10,6);cout<<"Masukkan Kode Barang [A, B, or C] : ";cin>>kode;
gotoxy(10,7);cout<<"Jumlah Beli : ";cin>>jml;
switch(kode)
{
case 'A':
gotoxy(10,9);cout<<"Nama Barang : Alat Olahraga";
harga=300000;
break;
case 'B':
gotoxy(10,9);cout<<"Nama Barang : Alat Elektronik";
harga=500000;
break;
case 'C':
gotoxy(10,9);cout<<"Nama Barang : Alat Memasak";
harga=100000;
break;
default:
gotoxy(10,8);cout<<"Salah Memasukkan KODE";
break;
}
total=jml*harga;
gotoxy(10,10);cout<<"Harga Barang : "<<harga;
gotoxy(10,11);cout<<"Total Bayar : "<<total;
gotoxy(10,13);cout<<"Inputkan Data Lagi [Y/y/T/t] : "; cin>>lagi;
if(lagi=='Y' || lagi=='y')
goto atas ;
else if(lagi=='T' || lagi=='t')
exit(0);
else
gotoxy(10,14);cout<<"=>Input SALAH . . .";
getch();
}
0 komentar:
Posting Komentar