Variable yang bertipe data char pada saat input hanya bisa menyimpan 1 karakter/huruf.bagaiman kalau pada saat input harus ada 2 huruf..??.
Berikut Latihan inputan lebih dari satu huruf untuk variable ber tipe data char
Contoh kasus
Kd Kereta | Nama Kereta | Kd Kelas | Nama Kelas | Harga |
SU | Senja Utama | EK BI EX | Eonomi Bisnis Executif | 80000 100000 150000 |
FU | Fajar Utama | EK BI EX | Eonomi Bisnis Executif | 85000 110000 160000 |
TJ | Tawang Jaya | EK BI EX | Eonomi Bisnis Executif | 70000 105000 165000 |
Rancangan tampilan :
Ketentuan :
Ø Kode kereta diinput
Ø Kode kelas diinput
Ø Jumlah beli diinput
Ø Total bayar=harga*jumlah beli
Jawaban :
# include<conio.h>
# include<stdio.h>
# include<iostream.h>
main()
{
char nm[20],kdkr[3],kdkl[3],*nmkr,*kls;
int hrg,jml,ttl;
clrscr();
cout<<endl;
cout<<endl;
cout<<" AGEN TIKET MAJU LANCAR"<<endl;
cout<<"-----------------------------------------------------------"<<endl;
cout<<"NAMA PEMESAN :";cin>>nm;
cout<<"MASUKAN KODE KERETA [SU|FU|TJ] : ";cin>>kdkr;
cout<<"MASUKAN KODE KELAS [EK|BI|EX] : ";cin>>kdkl;
cout<<"JUMLAH BELI : ";cin>>jml;
cout<<"------------------------------------------------------------"<<endl;
if(strcmpi(kdkr,"SU")==0)
{
if(strcmpi(kdkl,"EK")==0)
{
nmkr="Senja Utama";
kls="Ekonomi";
hrg=80000;
}
else if(strcmpi(kdkl,"BI")==0)
{
nmkr="Senja Utama";
kls="Bisnis";
hrg=100000;
}
else if(strcmpi(kdkl,"Ex")==0)
{
nmkr="Senja Utama";
kls="Executif";
hrg=150000;
}
}
else if(strcmpi(kdkr,"FU")==0)
{
if(strcmpi(kdkl,"EK")==0)
{
nmkr="Fajar Utama";
kls="Ekonomi";
hrg=85000;
}
else if(strcmpi(kdkl,"BI")==0)
{
nmkr="Fajar Utama";
kls="Bisnis";
hrg=110000;
}
else if(strcmpi(kdkl,"Ex")==0)
{
nmkr="Fajar Utama";
kls="Executif";
hrg=160000;
}
}
else if(strcmpi(kdkr,"TJ")==0)
{
if(strcmpi(kdkl,"EK")==0)
{
nmkr="Tawang Jaya";
kls="Ekonomi";
hrg=70000;
}
else if(strcmpi(kdkl,"BI")==0)
{
nmkr="Tawang Jaya";
kls="Bisnis";
hrg=105000;
}
else if(strcmpi(kdkl,"Ex")==0)
{
nmkr="Tawang Jaya";
kls="Executif";
hrg=165000;
}
}
ttl=jml*hrg;
cout<<endl;
cout<<endl;
cout<<" DATA PESANAN"<<endl;
cout<<"----------------------------------"<<endl;
cout<<"NAMA PEMESAN : "<<nm<<endl;
cout<<"NAMA KERETA : "<<nmkr<<endl;
cout<<"KELAS : "<<kls<<endl;
cout<<"HARGA : "<<hrg<<endl;
cout<<"JUMLAH BELI : "<<jml<<endl;
cout<<"----------------------------------"<<endl;
cout<<"TOTAL BAYAR : "<<ttl<<endl;
getch();
}
Tidak ada komentar:
Posting Komentar