Hai..
Kali ini saya akan berbagi mengenai tugas Algoritma & Pemrograman Else If Case
disini saya akan memberi contoh tentang :
program jasa naik pesawat
langsung saja..
ini adalah screen shootnya
dan ini adalah source codenya menggunakan borland C++
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <windows.h>
main( )
{
{
system ("color 9");
cout<<"\t\tNama : Adjie Krisnandy"<<endl;
cout<<"\t\tNIM : 12132469"<<endl;
cout<<"\t\t 12.1A.05"<<endl;
}
char kelas=0, ulang;
char napes [50];
long harga, total, bayar, kembali;
float jumlah;
awal :
puts("\t\t Program tiket pesawat");
puts("\t\t Jakarta - Malaysia");
puts("\t\t---------------------------");
cout<<"\t Masukkan Kode Pesawat [MPT/GRD/BTV] : ";cin>>napes;
cout<<"\t\tkelas pesawat : "<<endl;
cout<<"\t\t\t1. Executive "<<endl;
cout<<"\t\t\t2. Bisnis "<<endl;
cout<<"\t\t\t3. Ekonomi "<<endl;
cout<<"\t\tpilih kelas [1/2/3] : "; cin>>kelas;
if (strcmp(napes,"MPT")==0 ||strcmp(napes, "mpt")==0)
{
strcpy(napes, "MERPATI");
switch(kelas)
{
case '1':
harga=1500000;
break;
case '2':
harga=900000;
break;
case '3':
harga=700000;
break;
default:
cout<<"\t\tAnda Salah Memasukan Kode"<<endl<<endl;
goto awal;
}
}
else if (strcmp(napes,"GRD")==0 ||strcmp(napes, "grd")==0)
{
strcpy(napes, "GARUDA");
switch(kelas)
{
case '1':
harga=1200000;
break;
case '2':
cout<<"800000";
break;
case '3':
harga=400000;
break;
default:
cout<<"\t\tAnda Salah Memasukan Kode"<<endl<<endl;
goto awal;
}
}
else if (strcmp(napes,"BTV")==0 ||strcmp(napes, "btv")==0)
{
strcpy(napes, "BATAVIA");
switch(kelas)
{
case '1':
harga=1000000;
break;
case '2':
harga=700000;
break;
case '3':
harga=300000;
break;
default:
cout<<"\t\tAnda Salah Memasukan Kode"<<endl<<endl;
goto awal;
}
}
clrscr();
puts("\t\t Program tiket pesawat");
puts("\t\t Jakarta - Malaysia");
puts("\t\t---------------------------");
cout<<"\t\tNama pesawat\t: "<<napes<<endl;
cout<<"\t\tHarga Tiket\t: "<<harga<<endl;
cout<<"\t\tMasukkan jumlah tiket\t: "; cin>>jumlah;
total=harga*jumlah;
cout<<"\t\tTotal yang harus dibayar: "<<total<<endl;
cout<<"\t\tUang pembayaran \t: "; cin>>bayar;
kembali=bayar-total;
cout<<"\t\tSisa kembalian \t\t: "<<kembali<<endl<<endl<<endl;
puts("\t\tThis Program Created by Adjie Krisnandy \n");
puts("\t\t My NIM : 12132469 \n");
puts("\t\t 12.1A.05 \n");
cout<<"\t\t INGIN INPUT LAGI? [Y/N] :"; cin>>ulang;
if(ulang=='Y' || ulang=='y')
goto awal;
else
getch();
}
#include <conio.h>
#include <iostream.h>
#include <windows.h>
main( )
{
{
system ("color 9");
cout<<"\t\tNama : Adjie Krisnandy"<<endl;
cout<<"\t\tNIM : 12132469"<<endl;
cout<<"\t\t 12.1A.05"<<endl;
}
char kelas=0, ulang;
char napes [50];
long harga, total, bayar, kembali;
float jumlah;
awal :
puts("\t\t Program tiket pesawat");
puts("\t\t Jakarta - Malaysia");
puts("\t\t---------------------------");
cout<<"\t Masukkan Kode Pesawat [MPT/GRD/BTV] : ";cin>>napes;
cout<<"\t\tkelas pesawat : "<<endl;
cout<<"\t\t\t1. Executive "<<endl;
cout<<"\t\t\t2. Bisnis "<<endl;
cout<<"\t\t\t3. Ekonomi "<<endl;
cout<<"\t\tpilih kelas [1/2/3] : "; cin>>kelas;
if (strcmp(napes,"MPT")==0 ||strcmp(napes, "mpt")==0)
{
strcpy(napes, "MERPATI");
switch(kelas)
{
case '1':
harga=1500000;
break;
case '2':
harga=900000;
break;
case '3':
harga=700000;
break;
default:
cout<<"\t\tAnda Salah Memasukan Kode"<<endl<<endl;
goto awal;
}
}
else if (strcmp(napes,"GRD")==0 ||strcmp(napes, "grd")==0)
{
strcpy(napes, "GARUDA");
switch(kelas)
{
case '1':
harga=1200000;
break;
case '2':
cout<<"800000";
break;
case '3':
harga=400000;
break;
default:
cout<<"\t\tAnda Salah Memasukan Kode"<<endl<<endl;
goto awal;
}
}
else if (strcmp(napes,"BTV")==0 ||strcmp(napes, "btv")==0)
{
strcpy(napes, "BATAVIA");
switch(kelas)
{
case '1':
harga=1000000;
break;
case '2':
harga=700000;
break;
case '3':
harga=300000;
break;
default:
cout<<"\t\tAnda Salah Memasukan Kode"<<endl<<endl;
goto awal;
}
}
clrscr();
puts("\t\t Program tiket pesawat");
puts("\t\t Jakarta - Malaysia");
puts("\t\t---------------------------");
cout<<"\t\tNama pesawat\t: "<<napes<<endl;
cout<<"\t\tHarga Tiket\t: "<<harga<<endl;
cout<<"\t\tMasukkan jumlah tiket\t: "; cin>>jumlah;
total=harga*jumlah;
cout<<"\t\tTotal yang harus dibayar: "<<total<<endl;
cout<<"\t\tUang pembayaran \t: "; cin>>bayar;
kembali=bayar-total;
cout<<"\t\tSisa kembalian \t\t: "<<kembali<<endl<<endl<<endl;
puts("\t\tThis Program Created by Adjie Krisnandy \n");
puts("\t\t My NIM : 12132469 \n");
puts("\t\t 12.1A.05 \n");
cout<<"\t\t INGIN INPUT LAGI? [Y/N] :"; cin>>ulang;
if(ulang=='Y' || ulang=='y')
goto awal;
else
getch();
}
Semoga Bermanfaat
-AK-