Yes. Floating point numbers are those with a decimal point,
such as in the second run of the program.
The variable NUMBER
can hold floating point values.
INPUT
The INPUT
statement must use a variable as a place to put the
data it gets.
Remember that a variable is
a small amount of computer memory that has been given name.
There is nothing special about the variable used with INPUT
.
Here is the same program as before,
except that it uses a different variable name.
It will do exactly the same thing as the first version.
' Double a Number PRINT "Type a number" 'Ask the user for a number INPUT MyData 'Get it from the keyboard, put it in MyData PRINT MyData * 2 'Print twice the number. END
The variable should be the correct type for the expected input.
Remember (from chapter 3) that the last character of a variable name
indicates what the variable is expected to hold.
For example, a variable VALUE#
can potentially hold a
very big floating point number.
A variable DATA%
is expected to hold an integer
(no decimal point).
Here is a program that does input of an integer:
' Integer Input PRINT "Type an integer" 'Ask the user for an integer INPUT DATA% 'Get it from the keyboard, put it in DATA% PRINT DATA% * 2 'Print twice the number. END
Say that the user types 1.2 when the INPUT
statement
of this program asks for data.
What will the monitor show after the user hits "enter"?