Acorn Computers BBC Micro Model B w/8271 — Acorn BBC Micro Model B w/8271 User Guide Manual PDF (EN)

67 11 Input The previous chapter showed how to get information out of the computer and on to the screen. This chapter deals with getting things from the keyboard into the computer. When a program is running there will often be a need for it to request some information from the person at the keyboard. 10 PRINT "HOW OLD ARE YOU" 20 INPUT AGE 30 IF AGE 40 IF AGE = 18 THEN PRINT "CONGRATULATIONS ON BEING "; 50 IF AGE>18 THEN PRINT "YOU ARE PAST IT IF YOU ARE "; 70 PRINT ;AGE >RUN HOW OLD ARE YOU ?22 YOU ARE PAST IT IF YOU ARE 22 Line 20 of the above program prints a question mark on the screen and then takes in everything that is typed on the keyboard until RETURN is pressed.

Line 20 says INPUT AGE so the computer is expecting a number since AGE is a numeric variable rather than a string variable (see chapter 9). If words are supplied instead of numbers then the computer assumes that the number is zero. >RUN HOW OLD ARE YOU ?I DON'T KNOW YOU ARE TOO YOUNG AT 0 Because line 20 said INPUT AGE a number was expected. If you want to INPUT a string (word or group of words) then you must place a string variable (eg NAME$ ) on the input line. 10 PRINT "WHAT IS YOUR NAME" 20 INPUT NAME$ 30 PRINT "HELLO ";NAME$;" HOW ARE YOU?" >RUN WHAT IS YOUR NAME ?JOHN HELLO JOHN HOW ARE YOU?