Site pages
Current course
Participants
General
Topic 1
Topic 2
Topic 3
Topic 4
Topic 5
Topic 6
Topic 7
Topic 8
Topic 9
Topic 10
Topic 11
Topic 12
Topic 13
Topic 14
Topic 15
Topic 16
Topic 17
Topic 18
Topic 19
Topic 20
Topic 21
Topic 22
Topic 23
Topic 24
Topic 25
Topic 26
Topic 27
Topic 28
Topic 29
Topic 30
Topic 31
Topic 32
Topic 33
Topic 34
Topic 35
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 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