Sebagai contoh disini ada program pada POM bensin, Cara kerja program ini adalah :
User akan memasukkan nama terlebih dahulu, selanjutnya memilih 4 menu yang tampil setelah nama diisikan. diantaranya adalah :
1. Solar : Rp.4000.00
2. Premium : Rp.4500.00
3. Pertamax : Rp.5000.00
4. Keluar
Selanjutnya user memasukkan uang yang di bayarkan,maka program akan memberitahukan pecahan uang yang dibayarkan secara detail.
Nah..lihat dan pelajari contoh listing programnya dibawah ini :
#include<iostream.h>
#include<conio.h>
#include<iomanip>
int main()
{
int a, jumlah, rtsnrb, lmplhrb, splhrb, lmrb,
serb, lmrts, srts, lmplh, sisa;
float uang,liter;
char kembali,nama[100];
do {
clrscr();
cout<<endl;
cout<<" ========================================"<<endl;
cout<<" | SELAMAT DATANG DI POM BENSIN FAUYAN |"<<endl;
cout<<" ========================================"<<endl;
cout<<endl;
cout<<"Nama konsumen = ";cin>>nama;
cin.getline(nama,20);
cout<<endl;
cout<<" 1. Solar "<<setw(15)<<" : Rp.4000.00"<<endl;
cout<<" 2. Premium "<<setw(7)<<" : Rp.4500.00"<<endl;
cout<<" 3. Pertamax : Rp.5000.00"<<endl;
cout<<" 4. Keluar "<<endl;
cout<<endl;
cout<<"Masukkan pilihan anda = ";cin>>a;
switch(a)
{
case 1:
cout<<"Uang yang dibayarkan" <<setw(7)<< " = Rp.";cin>>uang;
cout<<endl;
liter=uang/4000;
rtsnrb = uang / 100000;
sisa = uang - (rtsnrb * 100000);
lmplhrb = sisa / 50000;
sisa = sisa - (lmplhrb * 50000);
splhrb = sisa / 10000;
sisa = sisa - (splhrb * 10000);
lmrb = sisa / 5000;
sisa = sisa - (lmrb * 5000);
serb = sisa / 1000;
sisa = sisa - (serb * 1000);
lmrts = sisa / 500;
sisa = sisa - (lmrts * 500);
srts = sisa / 100;
sisa = sisa - (srts * 100);
lmplh = sisa / 50;
sisa = sisa - (lmplh * 50);
if (rtsnrb > 0){
if (uang >= 100000)
cout << "Pecahan 100.000 ada" <<setw(6)<< " = " <<rtsnrb;cout<<" Lembar"<<endl;}
if (lmplhrb > 0){
if (uang >= 50000)
cout << "Pecahan 50.000 ada" <<setw(7)<< " = "<<lmplhrb;cout<<" Lembar"<<endl;}
if (splhrb > 0){
if (uang >= 10000)
cout << "Pecahan 10.000 ada" <<setw(7)<< " = "<<splhrb;cout<<" Lembar"<<endl;}
if (lmrb > 0){
if (uang >= 5000)
cout << "Pecahan 5.000 ada" <<setw(8)<< " = "<<lmrb;cout<<" Lembar"<<endl;}
if (serb > 0){
if (uang >= 1000)
cout << "Pecahan 1.000 ada" <<setw(8)<< " = "<<serb;cout<<" Lembar"<<endl;}
if (lmrts > 0){
if (uang >= 500)
cout << "Pecahan 500 ada" <<setw(10)<< " = "<<lmrts;cout<<" Koin"<<endl;}
if (srts > 0){
if (uang >= 100)
cout << "Pecahan 100 ada" <<setw(10)<< " = "<<srts;cout<<" Koin"<<endl;}
if (lmplh > 0){
if (uang >= 50)
cout << "Pecahan 50 ada" <<setw(11)<< " = "<<lmplh;cout<<" Koin"<<endl;}
if (sisa > 0){
if (uang >= 0)
cout << "Sisa pecahan ada" <<setw(9)<< " = "<<sisa;cout<<" Rupiah"<<endl; }
cout<<endl;
cout<<"Maka premium yang di dapat = "<<liter;cout<<" Liter"<<endl;
cout<<setiosflags(ios::fixed);
cout<<"Maka uang yang dibayarkan " <<setw(4)<< " = Rp."<<setprecision(2)<<uang;
break;
case 2:
cout<<"Uang yang dibayarkan" <<setw(7)<< " = Rp.";cin>>uang;
cout<<endl;
liter=uang/4500;
rtsnrb = uang / 100000;
sisa = uang - (rtsnrb * 100000);
lmplhrb = sisa / 50000;
sisa = sisa - (lmplhrb * 50000);
splhrb = sisa / 10000;
sisa = sisa - (splhrb * 10000);
lmrb = sisa / 5000;
sisa = sisa - (lmrb * 5000);
serb = sisa / 1000;
sisa = sisa - (serb * 1000);
lmrts = sisa / 500;
sisa = sisa - (lmrts * 500);
srts = sisa / 100;
sisa = sisa - (srts * 100);
lmplh = sisa / 50;
sisa = sisa - (lmplh * 50);
if (rtsnrb > 0){
if (uang >= 100000)
cout << "Pecahan 100.000 ada" <<setw(6)<< " = " <<rtsnrb;cout<<" Lembar"<<endl;}
if (lmplhrb > 0){
if (uang >= 50000)
cout << "Pecahan 50.000 ada" <<setw(7)<< " = "<<lmplhrb;cout<<" Lembar"<<endl;}
if (splhrb > 0){
if (uang >= 10000)
cout << "Pecahan 10.000 ada" <<setw(7)<< " = "<<splhrb;cout<<" Lembar"<<endl;}
if (lmrb > 0){
if (uang >= 5000)
cout << "Pecahan 5.000 ada" <<setw(8)<< " = "<<lmrb;cout<<" Lembar"<<endl;}
if (serb > 0){
if (uang >= 1000)
cout << "Pecahan 1.000 ada" <<setw(8)<< " = "<<serb;cout<<" Lembar"<<endl;}
if (lmrts > 0){
if (uang >= 500)
cout << "Pecahan 500 ada" <<setw(10)<< " = "<<lmrts;cout<<" Koin"<<endl;}
if (srts > 0){
if (uang >= 100)
cout << "Pecahan 100 ada" <<setw(10)<< " = "<<srts;cout<<" Koin"<<endl;}
if (lmplh > 0){
if (uang >= 50)
cout << "Pecahan 50 ada" <<setw(11)<< " = "<<lmplh;cout<<" Koin"<<endl;}
if (sisa > 0){
if (uang >= 0)
cout << "Sisa pecahan ada" <<setw(9)<< " = "<<sisa;cout<<" Rupiah"<<endl; }
cout<<endl;
cout<<"Maka solar yang di dapat" <<setw(4)<< " = "<<liter;cout<<" Liter"<<endl;
cout<<setiosflags(ios::fixed);
cout<<"Maka uang yang dibayarkan = Rp."<<setprecision(2)<<uang;
break;
case 3:
cout<<"Uang yang dibayarkan" <<setw(7)<< " = Rp.";cin>>uang;
cout<<endl;
liter=uang/5000;
rtsnrb = uang / 100000;
sisa = uang - (rtsnrb * 100000);
lmplhrb = sisa / 50000;
sisa = sisa - (lmplhrb * 50000);
splhrb = sisa / 10000;
sisa = sisa - (splhrb * 10000);
lmrb = sisa / 5000;
sisa = sisa - (lmrb * 5000);
serb = sisa / 1000;
sisa = sisa - (serb * 1000);
lmrts = sisa / 500;
sisa = sisa - (lmrts * 500);
srts = sisa / 100;
sisa = sisa - (srts * 100);
lmplh = sisa / 50;
sisa = sisa - (lmplh * 50);
if (rtsnrb > 0){
if (uang >= 100000)
cout << "Pecahan 100.000 ada" <<setw(6)<< " = " <<rtsnrb;cout<<" Lembar"<<endl;}
if (lmplhrb > 0){
if (uang >= 50000)
cout << "Pecahan 50.000 ada" <<setw(7)<< " = "<<lmplhrb;cout<<" Lembar"<<endl;}
if (splhrb > 0){
if (uang >= 10000)
cout << "Pecahan 10.000 ada" <<setw(7)<< " = "<<splhrb;cout<<" Lembar"<<endl;}
if (lmrb > 0){
if (uang >= 5000)
cout << "Pecahan 5.000 ada" <<setw(8)<< " = "<<lmrb;cout<<" Lembar"<<endl;}
if (serb > 0){
if (uang >= 1000)
cout << "Pecahan 1.000 ada" <<setw(8)<< " = "<<serb;cout<<" Lembar"<<endl;}
if (lmrts > 0){
if (uang >= 500)
cout << "Pecahan 500 ada" <<setw(10)<< " = "<<lmrts;cout<<" Koin"<<endl;}
if (srts > 0){
if (uang >= 100)
cout << "Pecahan 100 ada" <<setw(10)<< " = "<<srts;cout<<" Koin"<<endl;}
if (lmplh > 0){
if (uang >= 50)
cout << "Pecahan 50 ada" <<setw(11)<< " = "<<lmplh;cout<<" Koin"<<endl;}
if (sisa > 0){
if (uang >= 0)
cout << "Sisa pecahan ada" <<setw(9)<< " = "<<sisa;cout<<" Rupiah"<<endl; }
cout<<endl;
cout<<"Maka pertamax yang di dapat = "<<liter;cout<<" Liter"<<endl;
cout<<setiosflags(ios::fixed);
cout<<"Maka uang yang dibayarkan " <<setw(7)<< " = Rp."<<setprecision(2)<<uang;
break;
case 4:
cout<<endl;
cout<<"Ketik 'Y' untuk kembali ke menu!!!"<<endl;
break;
default :
cout<<endl;
cout<<"Masukkan angka 1 sampai 4 saja!!!"<<endl;
break;
}
cout<<endl;
cout<<endl;
cout<<"Kembali Ke menu (y/n) ?";cin>>kembali;
}while (kembali == 'y');
}
Berikut contoh tampilan programnya :
User akan memasukkan nama terlebih dahulu, selanjutnya memilih 4 menu yang tampil setelah nama diisikan. diantaranya adalah :
1. Solar : Rp.4000.00
2. Premium : Rp.4500.00
3. Pertamax : Rp.5000.00
4. Keluar
Selanjutnya user memasukkan uang yang di bayarkan,maka program akan memberitahukan pecahan uang yang dibayarkan secara detail.
Nah..lihat dan pelajari contoh listing programnya dibawah ini :
#include<iostream.h>
#include<conio.h>
#include<iomanip>
int main()
{
int a, jumlah, rtsnrb, lmplhrb, splhrb, lmrb,
serb, lmrts, srts, lmplh, sisa;
float uang,liter;
char kembali,nama[100];
do {
clrscr();
cout<<endl;
cout<<" ========================================"<<endl;
cout<<" | SELAMAT DATANG DI POM BENSIN FAUYAN |"<<endl;
cout<<" ========================================"<<endl;
cout<<endl;
cout<<"Nama konsumen = ";cin>>nama;
cin.getline(nama,20);
cout<<endl;
cout<<" 1. Solar "<<setw(15)<<" : Rp.4000.00"<<endl;
cout<<" 2. Premium "<<setw(7)<<" : Rp.4500.00"<<endl;
cout<<" 3. Pertamax : Rp.5000.00"<<endl;
cout<<" 4. Keluar "<<endl;
cout<<endl;
cout<<"Masukkan pilihan anda = ";cin>>a;
switch(a)
{
case 1:
cout<<"Uang yang dibayarkan" <<setw(7)<< " = Rp.";cin>>uang;
cout<<endl;
liter=uang/4000;
rtsnrb = uang / 100000;
sisa = uang - (rtsnrb * 100000);
lmplhrb = sisa / 50000;
sisa = sisa - (lmplhrb * 50000);
splhrb = sisa / 10000;
sisa = sisa - (splhrb * 10000);
lmrb = sisa / 5000;
sisa = sisa - (lmrb * 5000);
serb = sisa / 1000;
sisa = sisa - (serb * 1000);
lmrts = sisa / 500;
sisa = sisa - (lmrts * 500);
srts = sisa / 100;
sisa = sisa - (srts * 100);
lmplh = sisa / 50;
sisa = sisa - (lmplh * 50);
if (rtsnrb > 0){
if (uang >= 100000)
cout << "Pecahan 100.000 ada" <<setw(6)<< " = " <<rtsnrb;cout<<" Lembar"<<endl;}
if (lmplhrb > 0){
if (uang >= 50000)
cout << "Pecahan 50.000 ada" <<setw(7)<< " = "<<lmplhrb;cout<<" Lembar"<<endl;}
if (splhrb > 0){
if (uang >= 10000)
cout << "Pecahan 10.000 ada" <<setw(7)<< " = "<<splhrb;cout<<" Lembar"<<endl;}
if (lmrb > 0){
if (uang >= 5000)
cout << "Pecahan 5.000 ada" <<setw(8)<< " = "<<lmrb;cout<<" Lembar"<<endl;}
if (serb > 0){
if (uang >= 1000)
cout << "Pecahan 1.000 ada" <<setw(8)<< " = "<<serb;cout<<" Lembar"<<endl;}
if (lmrts > 0){
if (uang >= 500)
cout << "Pecahan 500 ada" <<setw(10)<< " = "<<lmrts;cout<<" Koin"<<endl;}
if (srts > 0){
if (uang >= 100)
cout << "Pecahan 100 ada" <<setw(10)<< " = "<<srts;cout<<" Koin"<<endl;}
if (lmplh > 0){
if (uang >= 50)
cout << "Pecahan 50 ada" <<setw(11)<< " = "<<lmplh;cout<<" Koin"<<endl;}
if (sisa > 0){
if (uang >= 0)
cout << "Sisa pecahan ada" <<setw(9)<< " = "<<sisa;cout<<" Rupiah"<<endl; }
cout<<endl;
cout<<"Maka premium yang di dapat = "<<liter;cout<<" Liter"<<endl;
cout<<setiosflags(ios::fixed);
cout<<"Maka uang yang dibayarkan " <<setw(4)<< " = Rp."<<setprecision(2)<<uang;
break;
case 2:
cout<<"Uang yang dibayarkan" <<setw(7)<< " = Rp.";cin>>uang;
cout<<endl;
liter=uang/4500;
rtsnrb = uang / 100000;
sisa = uang - (rtsnrb * 100000);
lmplhrb = sisa / 50000;
sisa = sisa - (lmplhrb * 50000);
splhrb = sisa / 10000;
sisa = sisa - (splhrb * 10000);
lmrb = sisa / 5000;
sisa = sisa - (lmrb * 5000);
serb = sisa / 1000;
sisa = sisa - (serb * 1000);
lmrts = sisa / 500;
sisa = sisa - (lmrts * 500);
srts = sisa / 100;
sisa = sisa - (srts * 100);
lmplh = sisa / 50;
sisa = sisa - (lmplh * 50);
if (rtsnrb > 0){
if (uang >= 100000)
cout << "Pecahan 100.000 ada" <<setw(6)<< " = " <<rtsnrb;cout<<" Lembar"<<endl;}
if (lmplhrb > 0){
if (uang >= 50000)
cout << "Pecahan 50.000 ada" <<setw(7)<< " = "<<lmplhrb;cout<<" Lembar"<<endl;}
if (splhrb > 0){
if (uang >= 10000)
cout << "Pecahan 10.000 ada" <<setw(7)<< " = "<<splhrb;cout<<" Lembar"<<endl;}
if (lmrb > 0){
if (uang >= 5000)
cout << "Pecahan 5.000 ada" <<setw(8)<< " = "<<lmrb;cout<<" Lembar"<<endl;}
if (serb > 0){
if (uang >= 1000)
cout << "Pecahan 1.000 ada" <<setw(8)<< " = "<<serb;cout<<" Lembar"<<endl;}
if (lmrts > 0){
if (uang >= 500)
cout << "Pecahan 500 ada" <<setw(10)<< " = "<<lmrts;cout<<" Koin"<<endl;}
if (srts > 0){
if (uang >= 100)
cout << "Pecahan 100 ada" <<setw(10)<< " = "<<srts;cout<<" Koin"<<endl;}
if (lmplh > 0){
if (uang >= 50)
cout << "Pecahan 50 ada" <<setw(11)<< " = "<<lmplh;cout<<" Koin"<<endl;}
if (sisa > 0){
if (uang >= 0)
cout << "Sisa pecahan ada" <<setw(9)<< " = "<<sisa;cout<<" Rupiah"<<endl; }
cout<<endl;
cout<<"Maka solar yang di dapat" <<setw(4)<< " = "<<liter;cout<<" Liter"<<endl;
cout<<setiosflags(ios::fixed);
cout<<"Maka uang yang dibayarkan = Rp."<<setprecision(2)<<uang;
break;
case 3:
cout<<"Uang yang dibayarkan" <<setw(7)<< " = Rp.";cin>>uang;
cout<<endl;
liter=uang/5000;
rtsnrb = uang / 100000;
sisa = uang - (rtsnrb * 100000);
lmplhrb = sisa / 50000;
sisa = sisa - (lmplhrb * 50000);
splhrb = sisa / 10000;
sisa = sisa - (splhrb * 10000);
lmrb = sisa / 5000;
sisa = sisa - (lmrb * 5000);
serb = sisa / 1000;
sisa = sisa - (serb * 1000);
lmrts = sisa / 500;
sisa = sisa - (lmrts * 500);
srts = sisa / 100;
sisa = sisa - (srts * 100);
lmplh = sisa / 50;
sisa = sisa - (lmplh * 50);
if (rtsnrb > 0){
if (uang >= 100000)
cout << "Pecahan 100.000 ada" <<setw(6)<< " = " <<rtsnrb;cout<<" Lembar"<<endl;}
if (lmplhrb > 0){
if (uang >= 50000)
cout << "Pecahan 50.000 ada" <<setw(7)<< " = "<<lmplhrb;cout<<" Lembar"<<endl;}
if (splhrb > 0){
if (uang >= 10000)
cout << "Pecahan 10.000 ada" <<setw(7)<< " = "<<splhrb;cout<<" Lembar"<<endl;}
if (lmrb > 0){
if (uang >= 5000)
cout << "Pecahan 5.000 ada" <<setw(8)<< " = "<<lmrb;cout<<" Lembar"<<endl;}
if (serb > 0){
if (uang >= 1000)
cout << "Pecahan 1.000 ada" <<setw(8)<< " = "<<serb;cout<<" Lembar"<<endl;}
if (lmrts > 0){
if (uang >= 500)
cout << "Pecahan 500 ada" <<setw(10)<< " = "<<lmrts;cout<<" Koin"<<endl;}
if (srts > 0){
if (uang >= 100)
cout << "Pecahan 100 ada" <<setw(10)<< " = "<<srts;cout<<" Koin"<<endl;}
if (lmplh > 0){
if (uang >= 50)
cout << "Pecahan 50 ada" <<setw(11)<< " = "<<lmplh;cout<<" Koin"<<endl;}
if (sisa > 0){
if (uang >= 0)
cout << "Sisa pecahan ada" <<setw(9)<< " = "<<sisa;cout<<" Rupiah"<<endl; }
cout<<endl;
cout<<"Maka pertamax yang di dapat = "<<liter;cout<<" Liter"<<endl;
cout<<setiosflags(ios::fixed);
cout<<"Maka uang yang dibayarkan " <<setw(7)<< " = Rp."<<setprecision(2)<<uang;
break;
case 4:
cout<<endl;
cout<<"Ketik 'Y' untuk kembali ke menu!!!"<<endl;
break;
default :
cout<<endl;
cout<<"Masukkan angka 1 sampai 4 saja!!!"<<endl;
break;
}
cout<<endl;
cout<<endl;
cout<<"Kembali Ke menu (y/n) ?";cin>>kembali;
}while (kembali == 'y');
}
Berikut contoh tampilan programnya :
bro gue coba kok eror ya mohon pencerahannya
ReplyDelete