Wednesday, June 19

INPUT Statement

The INPUT Statement is used to prepare the program for input from the keyboard during program execution.
Syntax
LN INPUT [Prompt string ;] List of Variables
Where,
LN      :       Line Number
Prompt String  :    Message displayed for data to be supplied during program execution.
List of Variable  : Contains the variable {s} that store data

  • The prompt string must be surrounded by double question marks, followed by a semicolon or comma and name of variables to which it will be assigned.
  •  If more than one variable is used, they must be separated by commas. Similarly, values entered for different variables should be separated by commas. 
  • The data entered is assigned to variable list. The number of data items supplied must be the same as the number of variables in the list.
  • The variable names in the list may be numeric, integer, string or sub scripted variable.
  • If it is necessary that the data supplied must be of the same type as the variable in the input statement.
  • Comma may be used , instead of semicolon, after prompt string to suppress the question mark.
  • When INPUT statement is encountered during program execution, the program halts (stops) and prints a question mark{?} {or the prompt string is displayed }, then you can enter data and if you press Enter, program execution continues.
  • Quotation marks are optioned in string type of data.
Examples 
The following are some of valid INPUT statements
1. 10  INPUT A
2. 20  INPUT A,B,C
3. 30 INPUT A$, A2$, B1, B2, C1%, C2%
4. 40 INPUT A, B$, D(5)

CS 5.7 Display on the screen for INPUT statement

Ok
LIST 
10    REM Learning the use of INPUT statement
20    REM Value of two numbers X and Y
30    INPUT X
40    INPUT Y
50    REM Addition of two numbers X and Y
60    LET A = X+Y
70    PRINT " VALUE OF X = "; X
80    PRINT " VALUE OF Y="  ; Y 
90    PRINT "ADDITION OF X AND Y = "; A
100  END
Ok
RUN
?   25
?   10
VALUE OF X = 25
VALUE OF Y = 10
ADDITION OF X AND Y = 35
Ok

CS 5.8 Display on the screen for INPUT statement
Ok
LIST 
10    REM Learning the use of INPUT statement
20    INPUT N$
30    INPUT C
40    INPUT A$
50    INPUT R
60    PRINT " MY NAME IS " ; N$
70    PRINT " I STUDY IN CLASS "; C
80    PRINT " MY SCHOOL'S NAME IS "; A$
90    PRINT " MY ROLL NO. IS "; R
100  END
Ok
RUN
?  SUMA SHAH
?  9
? EAST-POLE HIGH SCHOOL
? 26
MY NAME IS SUMA SHAH
I STUDY IN CLASS 9
MY SCHOOL'S NAME IS EAST POLE HIGH SCHOOL
MY ROLL NO IS 26 
         

     
        

No comments:

Post a Comment