Kamis, 01 Desember 2011

Contoh Program Turbo Basic Penggunaan Statement IF….THEN……ELSE…….

Berikut adalah contoh program untuk melakukan perhitungan nilai, pada program ini menggunakan statement IF….THEN….ELSE….


cls
input “Jumlah Data :”n
dim nim$(n)
dim nama$(n)
dim niltgs(n)
dim nilkuis(n)
dim niluts(n)
dim niluas(n)

‘proses input data
cls
for i = 1 to n
cls
print “input data ke”i
input “NIM =”nim$(i)
input “Nama =”nama$(i)
input “Nilai Tugas =”niltgs(i)
input “Nilai Kuis =”nilkuis(i)
input “Nilai UTS =”niluts(i)
input “Nilai UAS =”niluas(i)
next i

‘proses tampil data
cls
print
print “_________________________________________________________”
locate 3,1:print “:”
locate 3,6:print “NIM”
locate 3,13:print “:”
locate 3,21:print “N A M A”
locate 3,35:print “:”
locate 3,37:print “N. Angka”
locate 3,46:print “:”
locate 3,48:print “N. Huruf”
locate 3,57:print “:”
print “_________________________________________________________”

‘proses menampilkan data
for i = 1 to n
locate 4+i,1:print “:”
locate 4+i,3:print nim$(i)
locate 4+i,13:print “:”
locate 4+i,15:print nama$(i)
locate 4+i,35:print “:”
nilangka=.25*niltgs(i) + .15*nilkuis(i) + .25*niluts(i) + .35*niluas(i)
locate 4+i,37:print using “##.##”;nilangka
locate 4+i,46:print “:”

if nilangka > 80 then
huruf$=”A”
else
if nilangka > 65 then
huruf$=”B”
else
if nilangka > 55 then
huruf$=”C”
else
if nilangka > 45 then
huruf$=”D”
else
huruf$=”E”
end if
end if
end if
end if

locate 4+i,52:print huruf$
locate 4+i,57:print “:”
next i
print “_________________________________________________________”

Tidak ada komentar: