[next] [previous] [contents]

  6.1.1.1 INPUT Statement
  The INPUT statement interactively prompts the user for
  data. You can use the optional prompt string to clarify the
  input request by specifying the type and number of data
  elements required by the program. This is especially use-
  ful when the program contains many variables, or when
  someone else is running your program. For example:
  INPUT "PLEASE TYPE 3 INTEGERS" ;B% ,C% ,D%
  A% = B% + C% + D%
  PRINT "THEIR SUM IS"; A%
  END

  Output
  PLEASE TYPE 3 INTEGERS? 25,50,75



                                                      Return



THEIR SUM IS 150
  When your program runs, BASIC stops at each INPUT,
  LINPUT, or INPUT LINE statement, prints a string prompt,
  if specified, and an optional question mark ( ? ) followed by a
  space; it then waits for your input. By using either a comma
  or semicolon, you can affect the format of your string prompt
  as follows:

  .
        If you have a semicolon separating the input prompt
        string from the variable, BASIC prints the question mark
        and space immediately after the input prompt string.
  .
        If you have a comma separating the input prompt string
        from the variable, BASIC prints the input prompt string,
        skips to the next print zone, and then prints the question
        mark and space.

  See Section 6.2.1 for more information about print zones.
  For more information about formatting string prompts, see
  Section 6.1.1.3.

  You must provide one value for each variable in the INPUT
  request. If you do not provide enough values, BASIC prompts
  you again. For example:
  INPUT A,B
  END

  Output
  ? 5



          Return




  ? 6

          Return




  BASIC interprets a carriage return (null input) as a zero
  value for numeric variables and as a null string for string
  variables. For example:
  ? 5

          Return




  ?

          Return




  These responses assign the value 5 to variable A and zero to
  variable B . In contrast, if you provide more values than there
  are variables, BASIC ignores the excess.

  In the following example, BASIC ignores the extra value (8).
  Note that you can type multiple values if you separate them
  with commas. Because commas separate variables in the
  PRINT statement, BASIC prints each variable at the start of
  a print zone.
  INPUT A,B,C
  PRINT A,B,C
  END

  Output
  ? 5,6,7,8



                  Return




    5 6 7
  If you name a numeric variable in an INPUT statement, you
  must supply numeric data. If you supply string data to a nu-
  meric variable, BASIC signals ``Illegal number'' (ERR=52). If
  you supply a floating-point number for an integer variable,
  BASIC signals ``Data format error'' (ERR=50).

  If you name a string variable in an INPUT statement, you
  can supply either numbers or letters, but BASIC treats the
  data you supply as a string. Because digits and a decimal
  point are valid text characters, numbers can be interpreted as
  strings. For example:
  INPUT "Please type a number"; A$
  PRINT A$

  Output
  Please type a number? 25.5
  25.5
  BASIC interprets the response as a 4-character string instead
  of as a numeric value.

  You can type strings with or without quotation marks.
  However, if you want to input a string containing a comma,
  you should enclose the string in quotation marks or use the
  INPUT LINE or LINPUT statement. If you do not, BASIC
  treats the comma as a delimiter and assigns only part of the
  string to the variable. If you use quotation marks, be sure
  to type both beginning and ending marks. If you leave out
  the end quotation mark, BASIC signals ``Data format error''
  (ERR=50).