Inputan:
Output:
Koding:
#include <conio.h>
#include <iostream>
#include <stdio>
#include <iomanip>
//prototype function
garis();
subtotal(short b,int h);
main(){
//deklarasi variabel, * adl pointer
short d,x,beli[5];
char nama[20],kode[5],*namabarang[5],lagi;
int harga[5],total=0;
//inputan
atas:
clrscr();
cout<<"nama pembeli:
";gets(nama);
cout<<"jumlah
data: ";cin>>d;
for(x=1;x<=d;x++){
cout<<"data
ke-"<<x<<endl;
cout<<"kode
barang[1/2/3]: ";cin>>kode[x];
cout<<"jmh beli:
";cin>>beli[x];
//proses
if(kode[x]=='1'){
namabarang[x]="netbook";
harga[x]=2500000;}
else if(kode[x]=='2'){
namabarang[x]="tablet";
harga[x]=18000000;}
else if(kode[x]=='3'){
namabarang[x]="hp";
harga[x]=1500000;}
subtotal(beli[x],harga[x]);
}
//output
clrscr();
cout<<"Nama
pembeli:"<<nama<<endl;
garis();
cout<<"kodebarang namabarang
harga beli subtotal"<<endl;
garis();
for(x=1;x<=d;x++){
cout<<setiosflags(ios::left);
cout<<setw(3)<<kode[x];
cout<<setw(15)<<namabarang[x];
cout<<setw(15)<<harga[x];
cout<<setw(5)<<beli[x];
cout<<setw(15)<<subtotal(beli[x],harga[x])<<endl;
total=total+subtotal(beli[x],harga[x]);
}
garis();
cout<<"total
bayar:"<<total<<endl;
cout<<"input
lagi[y/t]?";cin>>lagi;
switch(lagi){
case 'y':
case 'Y':
goto atas;
break;
default:
cout<<"terima kasih";
break;
}
getch();}
//function
garis()
{
cout<<"================================================================"<<endl;
}
subtotal(short b,int h)
{
return(b*h);
}