Professional Documents
Culture Documents
❑ INKEY$
❑ RND Function
2
INKEY$ FUNCTION
The INKEY$ function gets input from the
keyboard. INKEY$ can get only one character at a
time from the keyboard, not an entire string of
characters, as INPUT can. Following is the syntax;
INKEY$
4
INKEY$ FUNCTION [EXAMPLE 1]
CLS
100 PRINT
PRINT
PRINT "Civil Engineering"
PRINT
PRINT
PRINT "Print again (Y/N)"
DO
ans$ = INKEY$
LOOP UNTIL ((UCASE$(ans$) = "Y") OR (UCASE$(ans$) = "N"))
IF UCASE$(ans$) = "Y" THEN GOTO 100
IF UCASE$(ans$) = "N" THEN END
END
5
INKEY$ FUNCTION [EXAMPLE 1]
6
INKEY$ FUNCTION [EXAMPLE 2]
CLS
PRINT "What do you want to do"
PRINT
PRINT "1. Calculate area of rectangle"
PRINT "2. Calculate area of triangle"
PRINT "3. Calculate area of circle"
PRINT
PRINT "Please press the number of your
choice..."
DO
choice$ = INKEY$
LOOP UNTIL ((choice$ = "1") OR (choice$ = "2")
OR (choice$ = "3"))
PRINT "You selected "; choice$
END
7
INKEY$ FUNCTION [EXAMPLE 2]
8
RND FUNCTION
RND is the function for generating a random
number. It gives a decimal fractional value between
0 and 1 (but never exactly 0 or 1)
Output
CLS
.7055475
PRINT RND
CLS
FOR i = 1 TO 20
PRINT INT(10*RND)+ 1
NEXT i
CLS
RANDOMIZE TIMER
PRINT INT(6 * RND) + 1
END
12
RND FUNCTION [EXAMPLE 1]
[EXAMPLE 1] Program to print 10 random numbers
from 1 to 100.
CLS
RANDOMIZE TIMER
FOR i = 1 TO 10
n(i)=INT(100*RND)+1
NEXT i
END
13
END OF LECTURE