EasyManua.ls Logo

Commodore 128 - Inputting Data with the Getkey Command; Sample Program

Commodore 128
448 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SAMPLE PROGRAM
This program calculates interest and loan payments, using some
of the commands and statements you just learned. It sets a
minimum value for the loan using the ELSE clause with an IF-
THEN statement, and sets up a dollar and cents format with
PRINT USING.
10 INPUT LOAN AMOUNT IN DOLLARS;A
20 IF A< 100 THEN 70: ELSE P=.15
30 l=A*P
40 ?TOTAL PAYMENT EQUALS;
50 PRINT USING # $ # # # # # .# # ;A+I
60 GOTO 80
70 ?LOANS OF UNDER $100 NOT AVAILABLE
80 END
INPUTTING DATA WITH THE GETKEY COMMAND
You have learned to use INPUT and GET commands to enter
DATA during a program. Another way for you to enter data while
a program is being RUN is with the GETKEY statement. The
GETKEY statement accepts only one key at a time. GETKEY is
usually followed by a string variable (A$ for example). Any key
that is pressed is assigned to that string variable. GETKEY is
useful because it allows you to enter data one character at a time
without having to press the RETURN key after each character.
The GETKEY statement may only be used in a program.
Here is an example of using GETKEY in a program.
1000 PRINT PLEASE CHOOSE A, B, C, D, E, OR F
1010 GETKEY A$
1020 PRINT A$; WAS THE KEY YOU PRESSED.
The computer waits until a single key is pressed; when the key is
pressed, the character is assigned to variable A$, and printed out
in line 1020. The following program features GETKEY in more
complex and useful fashions: for answering a multiple-choice
question and also asking if the question should be repeated. If the
answer given is incorrect, the user has the option to try again by
pressing the "Y key (line 80). The key pressed for the multiple
choice answer is assigned to variable A$ while the TRY AGAIN
5-8

Table of Contents

Other manuals for Commodore 128

Related product manuals