The INPUT statement

The INPUT statement


    We have seen that there are two ways of assigning values to variables:
    (i)by the assignment (LET) and (ii) by the statement pair DATA/READ. When these statements are used, values are specified in the program itself. No input device need be used for entering data values. However, there is another way by which variables may be allotted values. This is by the INPUT statement. The form of this statement is
    The_INPUT_statement.jpg
    where
    list --- represents the names of variables, simple or subscripted, separated
    by commas.
    Eg :
    44 INPUT X, Y, Z
    Now the values of the variables X, Y, Z are entered through the input device (i.e) through the keyboard. Whenever an INPUT statement is executed in the program, the computer writes a question mak (?) It is a signal to the user that he should now enter the data values for variables. The user then types the constants that are to become the values of variables appearing in the list of the INPUT statement. RESTORE statement can not be used with INPUT statement.
    Input “no of observatios”;n
    Print “no of observations”
    Input n
    Program:
    Develop a program to convert temperatures, given in degrees centigrade(C), to degrees Fahrenheit (F) using the formula
    F=(9/5)C +32
    10 REM TO CONVERT TEMPERATUER IN
    20 REM CENTIGRADE TO FAHRENHEIT
    30 PRINT “TEMP IN CENTIGRADE”;
    40 INPUT C
    50 LET F=(9/5)*C +32
    60 PRINT
    70 PRINT “TEMP IN FAHRENHEIT=”;F
    80 END
    When the program is executed, the INPUT statement of line 40 writes ? after the following message:
    TEMP IN CENTIGRADE ?
    You type the number 37 after the question mark and the line on the screen appear as :
    TEMP IN CENTIGRADE ? 37
    After this, press key ENTER and the output appear as
    TEMP IN FAHRENHEIT =98.6
    Some versions of BASIC allow specify the output message with the INPUT statement as well. The format appears as:
    l INPUT “message”, list
    eg:
    49 INPUT “ENTER VALUE OF RADIUS”, R
    Now the following appears on the screen
    ENTER VALUE OF RADIUS ?

Last modified: Wednesday, 18 January 2012, 11:10 PM