Home > Coretan Pribadi Gw, Tip And Trick, TIPS & TRICK, Windows > Fungsi IF, CASE, dan FOR C++ Bagian 1

Fungsi IF, CASE, dan FOR C++ Bagian 1

BERIKUT CONTOH SOURCE CODENYA :

# include <conio.h>
# include <iostream.h>
# include <stdio.h>
main (){
char kode[5],*nama[5],lagi;
long int harga[10],subtotal[5];
float total;
int i,j,jumbel;
awal:
clrscr();
cout <<“…:::TOKO ATK BAROKAH:::…”<<endl;
cout <<“=============================”<<endl;
cout <<endl;
cout << “Masukan Jumlah Beli Barang :”;cin>>j;
cout <<“=============================”<<endl;
cout <<endl;
for (i=1;i<=j;++i)
{
cout <<“Data Barang ke- :”<<i<<endl;
cout <<“Kode Barang [A||a & B||b] :”;cin>>kode[i];
switch (kode[i])
{
case ‘A’:
case ‘a’:
{ nama[i]=”Buku”;
harga[i]=2500;
}
break;
case ‘B’:
case ‘b’:
{ nama[i]=”Pensil”;
harga[i]=2000;
}
break;
default:
cout <<“=============================”<<endl;
cout<<“\tKode salah”<<endl;;
cout<<“\tMau input data lagi [Y/T] =”;cin>>lagi;
if (lagi==’Y’|| lagi==’y’)
goto awal;
else
goto akhir;
}
cout <<“=============================”<<endl;
cout <<“Nama barang :”<<nama[i]<<endl;
cout <<“Harga satuan :”<<harga[i]<<endl;
cout <<“Jumlah beli :”;cin>>jumbel;
subtotal[i]=jumbel*harga[i];
//total=total+subtotal[i];
cout <<“Subtotal :”<<subtotal[i]<<endl;
cout<<“___________________”<<endl;
total=total+subtotal[i];
}
cout <<“Gran total :”<<total <<endl;
cout <<“=============================”<<endl;
cout<<“\tMau input data lagi [Y/T] =”;cin>>lagi;
if (lagi==’Y’|| lagi==’y’)
goto awal;
else
goto akhir;
akhir:
getch();
}

SELAMAT MENCOBANYA KAWAN,ITU MASIH SEDERHANA LISTINGNYA…..

BERSAMBUNG………..

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: