ASSALAMUALAIKUM WR. WB.
Disini
saya akan memberikan contoh program dari penggunaan statement select case pada
program Qbasic. Jadi SELECT CASE itu adalah salah satu bentuk perintah
kondisi dalam Qbasic selain IF THEN.
Dengan konsep memberikan kemungkinan nilai variabel yang ingin dicari.
Contoh program select case :
Statement :
CLS
LOCATE 3, 25
PRINT “==========
menu pilihan ==========”
LOCATE 4, 25
PRINT “ 1. Gitar”
LOCATE 5, 25
PRINT “2. Keyboard”
LOCATE 6, 25
PRINT “3.
Bass”
LOCATE 7, 25
PRINT “4.
Drum”
LOCATE 8, 25
PRINT “5.Exit”
LOCATE 9, 25
PRINT “===============================”
PRINT
LOCATE 11, 25
INPUT “pilih
alat music (1/2/3/4/5) :”;pil
INPUT “masukkan
jumlah barang :’;jml
PRINT
SELECT CASE pil
CASE 1
PRINT “jenis
alat musik : gitar listrik Ibanez”
HB = 1700000
CASE 2
PRINT “jenis alat musik : yamaha keyboard PSR S910”
HB = 1100000
CASE 3
PRINT “jenis alat musik : bass Ibanez SRX300”
HB = 2900000
CASE 4
PRINT “jenis alat musik : drum pearl retrospec”
HB = 2300000
CASE ELSE
PRINT “jenis alat musik : kode yang anda masukkan salah”
END SELECT
SELECT CASE jml
CASE IS > 100
Total = HB * jml
Diskon = total –* 20/100
Bayar = total - diskon
CASE 2 TO 100
Total = HB * jml
Diskon = total –* 15/100
Bayar = total - diskon
CASE IS < 2
Total = HB * jml
Bayar = total – diskon
END SELECT
PRINT “jumlah barang : “ ; jml
PRINT “harga satuan : “ ; HB
PRINT “total : “ ;
total
PRINT “diskon : “ ; diskon
PRINT “=========================(-)”
PRINT “ bayar : “ ; bayar ; ; “”
END
Dan saat di run akan menghasilkan output berikut :
Kira-kira itu contoh sederhana penggunaan select
case. Mudah-mudah contoh program yang diatas berguna dan bermanfaat.
A Short Description about youself
Any feedback, questions or ideas are always welcome. In case you are posting Code ,then first escape it using Postify and then paste it in the comments
0 komentar: