Penggunaan IF & Case Pada Pascal
Program ContohIf;
uses crt;
var NF:string[10];
tgl:string[10];
np:string[15];
al:string[25];
nb:string[10];
kb:char;
tba,dis,tb,h,jp:real;
begin
clrscr;
writeln('ENTRY DATA TRANSAKSI');
writeln('====================');
write('No Faktur :');readln(nf);
write('Tgl. Transaksi :');readln(tgl);
write('Nama Pembeli :');readln(np);
write('Alamat :');readln(al);
write('Kode Barang A/B/C :');readln(kb);
write('Jumlah Pesan :');readln(jp);
if(kb='A') then begin nb:='BUKU'; H:=1000; end else
if(kb='B') then begin nb:='PENA'; H:=2000; end else
if(kb='C') then begin nb:='PENCIL'; H:=500; end else
begin nb:='Tidak Ada'; H:=0; end;
writeln;
writeln('Nama Barang :',nb);
writeln('Harga :',h:6:2);
writeln('Jumlah Pesan :',jp:6:2);
tb:=h*jp;
writeln('Total Bayar Sebelum Discount :',tb:6:2);
if jp>500 then dis:=0.1*tb else dis:=0;
writeln('DISCOUNT :',dis:6:2);
tba:=tb-dis;
writeln('Total Bayar Akhir :',tba:6:2);
readln;
end.
Program ContohIf;
uses crt;
var NF:string[10];
tgl:string[10];
np:string[15];
al:string[25];
nb:string[10];
kb:char;
tba,dis,tb,h,jp:real;
begin
clrscr;
writeln('ENTRY DATA TRANSAKSI');
writeln('====================');
write('No Faktur :');readln(nf);
write('Tgl. Transaksi :');readln(tgl);
write('Nama Pembeli :');readln(np);
write('Alamat :');readln(al);
write('Kode Barang A/B/C :');readln(kb);
write('Jumlah Pesan :');readln(jp);
case kb of
'A' : begin nb:='BUKU'; H:=1000; end;
'B' : begin nb:='PENA'; H:=2000; end;
'C' : begin nb:='PENCIL'; H:=500; end;
else begin nb:='Tidak Ada'; H:=0; end;
end;
writeln;
writeln('Nama Barang :',nb);
writeln('Harga :',h:6:2);
writeln('Jumlah Pesan :',jp:6:0);
tb:=h*jp;
writeln('Total Bayar Sebelum Discount :',tb:6:2);
if jp>500 then dis:=0.1*tb else dis:=0;
writeln('DISCOUNT :',dis:6:2);
tba:=tb-dis;
writeln('Total Bayar Akhir :',tba:6:2);
readln;
end.
uses crt;
var NF:string[10];
tgl:string[10];
np:string[15];
al:string[25];
nb:string[10];
kb:char;
tba,dis,tb,h,jp:real;
begin
clrscr;
writeln('ENTRY DATA TRANSAKSI');
writeln('====================');
write('No Faktur :');readln(nf);
write('Tgl. Transaksi :');readln(tgl);
write('Nama Pembeli :');readln(np);
write('Alamat :');readln(al);
write('Kode Barang A/B/C :');readln(kb);
write('Jumlah Pesan :');readln(jp);
if(kb='A') then begin nb:='BUKU'; H:=1000; end else
if(kb='B') then begin nb:='PENA'; H:=2000; end else
if(kb='C') then begin nb:='PENCIL'; H:=500; end else
begin nb:='Tidak Ada'; H:=0; end;
writeln;
writeln('Nama Barang :',nb);
writeln('Harga :',h:6:2);
writeln('Jumlah Pesan :',jp:6:2);
tb:=h*jp;
writeln('Total Bayar Sebelum Discount :',tb:6:2);
if jp>500 then dis:=0.1*tb else dis:=0;
writeln('DISCOUNT :',dis:6:2);
tba:=tb-dis;
writeln('Total Bayar Akhir :',tba:6:2);
readln;
end.
Program ContohIf;
uses crt;
var NF:string[10];
tgl:string[10];
np:string[15];
al:string[25];
nb:string[10];
kb:char;
tba,dis,tb,h,jp:real;
begin
clrscr;
writeln('ENTRY DATA TRANSAKSI');
writeln('====================');
write('No Faktur :');readln(nf);
write('Tgl. Transaksi :');readln(tgl);
write('Nama Pembeli :');readln(np);
write('Alamat :');readln(al);
write('Kode Barang A/B/C :');readln(kb);
write('Jumlah Pesan :');readln(jp);
case kb of
'A' : begin nb:='BUKU'; H:=1000; end;
'B' : begin nb:='PENA'; H:=2000; end;
'C' : begin nb:='PENCIL'; H:=500; end;
else begin nb:='Tidak Ada'; H:=0; end;
end;
writeln;
writeln('Nama Barang :',nb);
writeln('Harga :',h:6:2);
writeln('Jumlah Pesan :',jp:6:0);
tb:=h*jp;
writeln('Total Bayar Sebelum Discount :',tb:6:2);
if jp>500 then dis:=0.1*tb else dis:=0;
writeln('DISCOUNT :',dis:6:2);
tba:=tb-dis;
writeln('Total Bayar Akhir :',tba:6:2);
readln;
end.
thanks bro... sangat bermanfaat nihh..
ReplyDeletemasama sob
Delete