Contoh program Menggunakan Kode pembelian 2 karakter/lebih


Program ini adalah program PENJUALAN DVD, yang diamana pada listing kali ini sedikit berbeda karena saya menggunakan perintah !strcmp.
berikut ini perbedaannya
listing 1.  if ((!strcmp (kode,"FT"))||(!strcmp (kode,"ft")))
listing 2. if (kode=="FT"||kode=="ft")

Bisa anda coba sendiri perbedaannya,dimana listing 2 akan terjadi error karena listing tersebut tidak bisa menggunakan 2 karakter/lebih, 2 karakter disini maksudnya yaitu kode=="FT" nah FT ini dihitung 2 karakter, jadi untuk membuat kondisi dengan kode 2 karakter/lebih harus menggunakan strcmp.

Berikut ini contoh program saya buat dimana kode yg saya gunakan menggunakan 2 dan 3 karakter :

Anda bisa download kodenya disini: Download Kode
Atau bisa anda copy paste kode dibawah ini:

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

main()
{
char tgl[20],pk[30],np[30],kode[2],jd[5],*jf,lagi,awal;
int jb,harga,th;
float diskon,jumb,ub,uk;
awal:
cout<<"I. Tampilan Input\n-----------------------------\nToko CD/DVD Kirei No Hikari\n-----------------------------\n";
cout<<"Tanggal            = ";gets(tgl);
cout<<"Petugas Kasir      = ";gets(pk);
cout<<"Nama Pelanggan     = ";gets(np);
cout<<"Kode Judul Film    = ";cin>>kode;
cout<<"Jenis Disk         = ";cin>>jd;
cout<<"Jumlah Beli        = ";cin>>jb;
clrscr();
cout<<"II. Tampilan Output\n-----------------------------\nToko CD/DVD Kirei No Hikari\n-----------------------------\n";
cout<<"Tanggal            = "<<tgl<<endl;
cout<<"Petugas Kasir      = "<<pk<<endl;
cout<<"Nama Pelanggan     = "<<np<<endl;
if ((!strcmp (kode,"FT"))||(!strcmp (kode,"ft")))
{jf="Fairy Tail";
 if ((!strcmp (jd,"cd"))||(!strcmp (jd,"CD")))
 harga=20000;
 else if ((!strcmp (jd,"DVD"))||(!strcmp (jd,"dvd")))
 harga=40000;
}
else if ((!strcmp (kode,"OP"))||(!strcmp (kode,"op")))
{jf="One Piece";
 if ((!strcmp (jd,"cd"))||(!strcmp (jd,"CD")))
 harga=20000;
 else if ((!strcmp (jd,"DVD"))||(!strcmp (jd,"dvd")))
 harga=40000;
}
else if ((!strcmp (kode,"bc"))||(!strcmp (kode,"bc")))
{jf="Bleach";
 if ((!strcmp (jd,"cd"))||(!strcmp (jd,"CD")))
 harga=19000;
 else if ((!strcmp (jd,"DVD"))||(!strcmp (jd,"dvd")))
 harga=38000;
}
else if ((!strcmp (kode,"dm"))||(!strcmp (kode,"DM")))
{jf="Doraemon";
 if ((!strcmp (jd,"cd"))||(!strcmp (jd,"CD")))
 harga=15000;
 else if ((!strcmp (jd,"DVD"))||(!strcmp (jd,"dvd")))
 harga=35000;
}
else if ((!strcmp (kode,"NT"))||(!strcmp (kode,"nt")))
{jf="Naruto";
 if ((!strcmp (jd,"cd"))||(!strcmp (jd,"CD")))
 harga=18000;
 else if ((!strcmp (jd,"DVD"))||(!strcmp (jd,"dvd")))
 harga=40000;
}
else if ((!strcmp (kode,"vk"))||(!strcmp (kode,"VK")))
{jf="Vampire Knight";
 if ((!strcmp (jd,"cd"))||(!strcmp (jd,"CD")))
 harga=10000;
 else if ((!strcmp (jd,"DVD"))||(!strcmp (jd,"dvd")))
 harga=35000;
}
else if ((!strcmp (kode,"sc"))||(!strcmp (kode,"SC")))
{jf="Sinchan";
 if ((!strcmp (jd,"cd"))||(!strcmp (jd,"CD")))
 harga=10000;
 else if ((!strcmp (jd,"DVD"))||(!strcmp (jd,"dvd")))
 harga=25000;
}
else if ((!strcmp (kode,"lg"))||(!strcmp (kode,"LG")))
{jf="Lets In Go";
 if ((!strcmp (jd,"cd"))||(!strcmp (jd,"CD")))
 harga=10000;
 else if ((!strcmp (jd,"DVD"))||(!strcmp (jd,"dvd")))
 harga=30000;
}
else if ((!strcmp (kode,"dz"))||(!strcmp (kode,"DZ")))
{jf="Dragonbal Z";
 if ((!strcmp (jd,"cd"))||(!strcmp (jd,"CD")))
 harga=15000;
 else if ((!strcmp (jd,"DVD"))||(!strcmp (jd,"dvd")))
 harga=35000;
}
else if ((!strcmp (kode,"B1"))||(!strcmp (kode,"b1")))
{jf="Ben 10";
 if ((!strcmp (jd,"cd"))||(!strcmp (jd,"CD")))
 harga=13000;
 else if ((!strcmp (jd,"DVD"))||(!strcmp (jd,"dvd")))
 harga=35000;
}
else if ((!strcmp (kode,"AA"))||(!strcmp (kode,"aa")))
{jf="Avatar Aang";
 if ((!strcmp (jd,"cd"))||(!strcmp (jd,"CD")))
 harga=12000;
 else if ((!strcmp (jd,"DVD"))||(!strcmp (jd,"dvd")))
 harga=28000;
}
else if ((!strcmp (kode,"pn"))||(!strcmp (kode,"PN")))
{jf="Pokemon";
 if ((!strcmp (jd,"cd"))||(!strcmp (jd,"CD")))
 harga=10000;
 else if ((!strcmp (jd,"DVD"))||(!strcmp (jd,"dvd")))
 harga=25000;
}
else if ((!strcmp (kode,"DN"))||(!strcmp (kode,"DN")))
{jf="Digimon";
 if ((!strcmp (jd,"cd"))||(!strcmp (jd,"CD")))
 harga=10000;
 else if ((!strcmp (jd,"DVD"))||(!strcmp (jd,"dvd")))
 harga=25000;
}
else if ((!strcmp (kode,"DC"))||(!strcmp (kode,"dc")))
{jf="Detektif Conan";
 if ((!strcmp (jd,"cd"))||(!strcmp (jd,"CD")))
 harga=20000;
 else if ((!strcmp (jd,"DVD"))||(!strcmp (jd,"dvd")))
 harga=40000;
}
else if ((!strcmp (kode,"ie"))||(!strcmp (kode,"IE")))
{jf="Izuma Eleven";
 if ((!strcmp (jd,"cd"))||(!strcmp (jd,"CD")))
 harga=11000;
 else if ((!strcmp (jd,"DVD"))||(!strcmp (jd,"dvd")))
 harga=33000;
}
else
{jf="Maaf Anda Salah Kode!!";
 if ((!strcmp (jd,"cd"))||(!strcmp (jd,"CD")))
 harga=0;
 else if ((!strcmp (jd,"DVD"))||(!strcmp (jd,"dvd")))
 harga=0;
}
cout<<"Jenis Film         = "<<jf<<endl;
cout<<"Harga CD/DVD       = "<<harga<<endl;
cout<<"Jumlah Beli        = "<<jb<<endl;
th=harga*jb;
cout<<"Total Harga        = "<<th<<endl;
if (jb>2)
 diskon=0.05*th;
else if (jb>5)
 diskon=0.1*th;
else if (jb>9)
 diskon=0.15*th;
else
cout<<"Ups Gak Dapet Diskon";
cout<<"Diskon             = "<<diskon<<endl;
jumb=th-diskon;
cout<<"Jumlah Bayar       = "<<jumb<<endl;
cout<<"--------------------------------------";
cout<<"Uang Bayar         = ";cin>>ub;
uk=ub-jumb;
cout<<"Uang Kembali       = "<<uk<<endl;
cout<<"**************************************";
if (lagi=='y'||lagi=='Y')
 goto awal;
else
cout<<"~~~~~~~~~~~Arigatou Gozaimasu~~~~~~~~~~~";
getch();
}

Semoga Bermanfaat, GOOD LUCK :D

Share this

Related Posts

Previous
Next Post »

1 comments:

comments
Anonymous
November 1, 2013 at 12:11 PM delete

#include
#include
#include

main()
{
char kode[3],*merk,ukuran,nm[20],no[15];
long harga,jml,total,kembali,byr;

cout<<"\t\tJAKET SERBA NYAMAN \n";
cout<<"==================================================="<>no;
cout<<"==================================================="<>kode;
cout<<"Ukuran[s/m/l]: ";cin>>ukuran;
cout<<"Jumlah Beli : ";cin>>jml;
if (kode==’1’)
{
merk="Eiger";
if (ukuran=='s' || 'S')
harga=150000;
else if (ukuran=='m' || 'M')
harga=220000;
else
harga=250000;
}
else
{
merk="Polo";
if (ukuran=='s'||'S')
harga=100000;
else if (ukuran=='m' || 'M')
harga=150000;
else
harga=200000;
}
cout<<"Merek Barang : "<>byr;
kembali=byr-total;
cout<<"Kembali : "<<kembali<<endl;
cout<<"==================================================="<<endl;
getch();
}
mau nanya deh knpa yayg eiger kalo sudah dirun ga muncul?

Reply
avatar

terimakasih telah berkunjung dan berkomentar :D