Kali ini saya akan memberikan contoh scrip Pembelian Tiket Pesawat pada Borland C++ di dalam program menggunakan IF Else Majemuk dan GOTO.
Silahkan Salin Scrip yang di bawah untuk di Pelajari.
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
main ()
{
char kode[4],*napes,bk[8],lagi;
int c1,c2,c3,jubel,harga,total;
atas:
clrscr();
cout<<" PROGRAM TIKET PESAWAT"<<endl;
cout<<" JAKARTA-MALAYSIA"<<endl;
cout<<"--------------------------------------------"<<endl;
cout<<endl;
cout<<" Masukan Kode Pesawat [MPT/GRD/BVT]: ";cin>>kode;
cout<<"Kelas Pesawat:"<<endl;
cout<<" 1.Executive"<<endl;
cout<<" 2.Bisnis"<<endl;
cout<<" 3.Ekonomi"<<endl;
cout<<" Pilih kelas [1/2/3]: ";cin>>bk;
c1=strcmp(kode,"MPT");c2=strcmp(kode,"GRD");c3=strcmp(kode,"BVT");
if (c1==0||c1==32)
{
napes="Merpati";
if(bk=="1")
{
harga=1500000;
}
else if(bk=="2")
{
harga=900000;
}
else{ harga=500000;}
}
else if( c2==0||c2==32)
{
napes="Garuda";
if(bk=="1")
{
harga=1200000;
}
else if(bk=="2")
{
harga=800000;
}
else {harga=400000;}
}
else if (c3==0||c3==32 )
{
napes="Batavia";
if(bk=="1")
{
harga=1000000;
}
else if(bk=="2")
{
harga=700000;
}
else {harga=300000; }
}
cout<<" Nama pesawat : "<<napes<<endl;
cout<<" Harga tiket : "<<harga<<endl;
cout<<" Jumlah Beli : ";cin>>jubel;
total=harga*jubel;
cout<<" Total Bayar : "<<total<<endl;
cout<<"\n\Ingin Input Lagi [Y/T] : ";cin>>lagi;
if (lagi == 'Y' || lagi == 'y')
goto atas;
getch();
}
#include <conio.h>
#include <iostream.h>
main ()
{
char kode[4],*napes,bk[8],lagi;
int c1,c2,c3,jubel,harga,total;
atas:
clrscr();
cout<<" PROGRAM TIKET PESAWAT"<<endl;
cout<<" JAKARTA-MALAYSIA"<<endl;
cout<<"--------------------------------------------"<<endl;
cout<<endl;
cout<<" Masukan Kode Pesawat [MPT/GRD/BVT]: ";cin>>kode;
cout<<"Kelas Pesawat:"<<endl;
cout<<" 1.Executive"<<endl;
cout<<" 2.Bisnis"<<endl;
cout<<" 3.Ekonomi"<<endl;
cout<<" Pilih kelas [1/2/3]: ";cin>>bk;
c1=strcmp(kode,"MPT");c2=strcmp(kode,"GRD");c3=strcmp(kode,"BVT");
if (c1==0||c1==32)
{
napes="Merpati";
if(bk=="1")
{
harga=1500000;
}
else if(bk=="2")
{
harga=900000;
}
else{ harga=500000;}
}
else if( c2==0||c2==32)
{
napes="Garuda";
if(bk=="1")
{
harga=1200000;
}
else if(bk=="2")
{
harga=800000;
}
else {harga=400000;}
}
else if (c3==0||c3==32 )
{
napes="Batavia";
if(bk=="1")
{
harga=1000000;
}
else if(bk=="2")
{
harga=700000;
}
else {harga=300000; }
}
cout<<" Nama pesawat : "<<napes<<endl;
cout<<" Harga tiket : "<<harga<<endl;
cout<<" Jumlah Beli : ";cin>>jubel;
total=harga*jubel;
cout<<" Total Bayar : "<<total<<endl;
cout<<"\n\Ingin Input Lagi [Y/T] : ";cin>>lagi;
if (lagi == 'Y' || lagi == 'y')
goto atas;
getch();
}
0 komentar:
Posting Komentar