Senin, 29 Oktober 2012

Contoh if else pesawat dengan C++


#include<conio.h>
#include<iostream.h>
main()
{
  awal:
  clrscr();
  int kode_kelas,jumlah,total,harga;
  char namapesawat[20],kode[3],lagi;
  cout<<"\t\t\tProgram Tiket Pesawat \n";
  cout<<"\t\t\tJAKARTA - MALAYSIA \n";
  cout<<"-------------------------------------------------------------------\n";
  cout<<endl;
  cout<<"Masukkan Kode Pesawat [MPT/GRD] : ";cin>>kode;
  cout<<"Kelas Pesawat : \n";
  cout<<"\t1. Executive\n";
  cout<<"\t2.Bisnis\n";
  cout<<"Pilih Kelas [1/2/3] : ";cin>>kode_kelas;
    if(strcmp(kode, "MPT")==0)  {
        strcpy(namapesawat, "merpati");
        if(kode_kelas==1)
              harga=150000;
        else if(kode_kelas==2)
              harga=900000;
        else if(kode_kelas==3)
              harga=500000;   }
    if(strcmp(kode, "GRD")==0)  {
        strcpy(namapesawat, "GARUDA");
        if(kode_kelas==1)
              harga=1200000;
        else if(kode_kelas==2)
              harga=800000;
        else if(kode_kelas==3)
              harga=400000;   }
  cout<<"Nama Pesawat  : "<<namapesawat<<endl;
  cout<<"Harga Tiket   : "<<harga<<endl;
  cout<<"Jumlah Tiket  : ";cin>>jumlah;
  total=harga*jumlah;
  cout<<"Total Bayar   : "<<total<<endl;
  cout<<"\n\t\t INGIN INPUT LAGI? [Y/T] : "; cin>>lagi;
  if(lagi=='Y'||lagi=='Y')
     goto awal;
  getch();
}


Tidak ada komentar:

Posting Komentar