The second program.

There is very little point in a program that outputs something but has no input. So for our second program we will use the command INPUT.

10 PRINT “Input first number “
20 INPUT x
30 PRINT “Input second number”
40 INPUT y
50 PRINT “X + Y is”, x + y

INPUT will get two numbers that you type in the command prompt. It ignores any non-numeric characters, and translates the first number that you see.

The comma separates items to print, and also tells the computer to insert a space.

It is also possible to input strings of characters. To do this, we use what is called a “string variable”. A string variable always ends with the dollar character ($), and contains text rather than numbers.

10 PRINT “What is your name?”
20 INPUT n$
30 PRINT “Hello”, n$

When inputting a string, INPUT reads up to the newline (which it discards).

We can use the ‘+’ operator, but not any others, on string variables.

10 PRINT “What is your first name?”
20 INPUT fname$
30 PRINT “What is your second name?”
40 INPUT sname$
50 PRINT “Hello”, fname$ + sname$

Notice that this program has a bug. The ‘+’ operator doesn’t insert a space, so unless you inadvertently added a space the program prints “FREDBLOGGS”. Try modifying the program by inserting a space between the two names.