Commodore 64 User Manual page 56

Hide thumbs Also See for 64:
Table of Contents

Advertisement

Or, just:
INPUT VARIABLE
NOTE: To get out of this program hold down the
um M
6
keys.
MIsI
and
The following program is not only useful, but demonstrates a lot of
what has been presented so far, including the new input statement.
NEW
1 F:EM TEMF'ERATI_IF:E C:ONVERICON PRC'GF:A19
5 PR I NT " { i_ LF:;•'HCit'lE)
10
20
341
40
50
60
70
8 0
PRINT "CONVERT FF:COM FAHRENHEIT OR CELSIUS
F/C'" : INF'CIT A:
I F A$ = "y' THEN 20
IF AS _ "F" THEN 100
IF AF <? "C" THEN 10
INPUT "ENTER DEO±REES CEL=:I U'_ : ".:C
F = :C*9: '/5+ 2
PRINT C;" DEC;. CELSIUS F;" DEG.
FAHRENHEIT"
PRINT
_:fO i 0Ti1 10
100 INPUT "ENTER DEGREE FAHRENHEIT: ";F
1 10 C. = (:: F- ? *5r'99
120 PRINT F:" DES=.
C:EL!-:; I US
1:300 PRINT
14e0 GCITO 10
FAHRENHEIT = "; C_.;" DEG.
If you enter and run this program, you'll see INPUT in action.
Line 10 uses the input statement to not only gather information, but
also print our prompt. Also notice that we can ask for either a number or
string (by using a numeric or string variable).
Lines 20, 30, and 40 do some checks on what is typed in. In line 20, if
nothing is entered (just ^ is hit), then the program goes back to
line 10 and requests the input again. In line 30, if F is typed, you know
the user wants to convert a temperature in degrees Fahrenheit to Cel-
sius, so the program branches to the part that does that conversion.
Line 40 does one more check. We know there are only two valid
choices the user can enter. To get to line 40, the user must have typed
some character other than F. Now, a check is made to see if that char-
acter is a C; if not, the program requests input 'again.
This may seem like a lot of detail, but it is good programming prac-

Hide quick links:

Advertisement

Table of Contents
loading

Related Products for Commodore 64

Table of Contents