Sabtu, 01 Desember 2012

CONTOH PENGGUNAAN ARRAY PADA C++


#include<iostream.h>
#include<conio.h>
#include<iomanip.h>

void main()
{
int n,i,harga,bayar=0,totalbayar,total[100],banyak[100]; //contoh ARRAY
float pajak;
char jenis[100];
cout << "Banyak Jenis  =  ";
cin>>n;
for (i=0;i<n;i++)
{
cout<<"Jenis ke-"<<(i+1) << endl;
cout<<"Jenis Potong [D/P/S] : ";
cin>>jenis[i];
cout<<"Banyak Potong        : ";
cin>>banyak[i];
cout<<endl;
}
clrscr();
cout<<"-------------------------------------------------------------------------------\n";
cout<<"No\tJenis Potong\tHarga Satuan\tBanyak Barang\tJumlah Harga\n";
cout<<"-------------------------------------------------------------------------------\n";
for(i=0;i<n;i++)
{
cout<<setw(9)<<setiosflags(ios::left)<<(i+1);         //Merapihkan Tampilan
cout<<setw(17)<< setiosflags(ios::left);
if(jenis[i]=='D'||jenis[i]=='d')
{
 cout<<"Dada";
 cout<<setw(17)<< setiosflags(ios::left);
 harga=2500;
 cout<<"2500";
}
else if (jenis[i]=='P'||jenis [i]=='p')
{
cout<<"Paha";
cout<<setw(17)<< setiosflags(ios::left);
harga=2000;
cout<<"2000";
}
else
{
 cout<<"Sayap";
 cout<<setw(17)<< setiosflags(ios::left);
 harga=1500;
 cout<<"1500";
}
cout<<setw(17)<< setiosflags(ios::left)<<banyak[i];
total[i]=banyak[i]*harga;
cout<<total[i];
bayar+=total [i];
cout<<endl ;
}
cout << endl ;
cout <<"--------------------------------------------------------------------------------\n";
cout<< "\t\t\t\t\tJumlah Bayar  =     "<<bayar<< endl ;
pajak = 0.1*bayar;
cout<< "\t\t\t\t\tPajak         =     "<<pajak<<endl;
totalbayar = bayar+pajak;
cout<< "\t\t\t\t\tToyal Bayar   =     "<<totalbayar<<endl<<endl ;
cout<<"----------------------------------Thank You--------------------------------------\n";
cout<<"hafizah program";
}

Tidak ada komentar:

Posting Komentar