Rabu, 10 April 2013

C++ Latihan Menggunakan Array,Switch case Dan Looping

#include <conio.h>
#include <stdio.h>
#include <iostream.h>
#include <iomanip.h>
judul()
{cout<<      "GEROBAK FRIED CHIKEN"<<endl;
cout<<"========================================="<<endl;
cout<<"  KODE      JENIS     HARGA            "<<endl;
cout<<"========================================="<<endl;}
main()
{
char kode[10],*jenis[10];
int i,j,harga[10],jml[10],total[10],pajak;
 long int tobay,totbay ;
judul();
cout<<"D      Dada         Rp.2500        "<<endl;
cout<<"P      Paha         Rp.2000        "<<endl;
cout<<"S      Sayap         Rp.1500        "<<endl;
cout<<"========================================="<<endl;
cout<<"Banyak Jenis        :";cin>>j;
for(i=1;i<=j;i++)
{
cout<<"Jenis Ke    :"<<i<<endl;
cout<<"Jenis Potong[D/P/S]    :";cin>>kode[i];
cout<<"Banyak Potong            :";cin>>jml[i];

switch (kode[i])
{
case 'D':
case 'd':
jenis[i]="Dada";
harga[i]=2500;
break;

case 'P':
case 'p':
jenis[i]="Paha";
harga[i]=2000;
break;

case 'S':
case 's':
jenis[i]="Sayap";
harga[i]=1500;
break;
default:
jenis[i]="Belum Tersedia";
harga[i]=0;
}
total[i]=jml[i]*harga[i];
}
clrscr();
judul();

for(i=1;i<=j;i++)
{
cout<<setiosflags(ios::left)<<setw(2)<<i;
cout<<setiosflags(ios::left)<<setw(4)<<kode[i];
cout<<setiosflags(ios::left)<<setw(8)<<jenis[i];
cout<<setiosflags(ios::left)<<setw(10)<<harga[i];
cout<<setiosflags(ios::left)<<setw(10)<<jml[i];
cout<<setiosflags(ios::left)<<setw(10)<<total[i]<<endl;
tobay=total[i]+tobay;
pajak=0.1*tobay;
totbay=tobay+pajak;
}
cout<<"TOTAL            :"<<tobay<<endl;
cout<<"PAJAK            :"<<pajak<<endl;
cout<<"TOTAL BAYAR    :"<<totbay<<endl;
getch();
}













Tidak ada komentar :

Posting Komentar