So far, we have learned to use the PRINT command to get the computer to print lines of text. This lesson will show you how to get the computer to ask you questions. This is done with the INPUT statment. Like the PRINT command, INPUT allows text to be displayed. However, it also allows the user to enter data and temporarily store it in the computer.
10 INPUT "This is what would be printed on the screen";variableThe INPUT command can be used to enter numbers or words (strings). Numbers can be added, subtracted, multiplied, divided, and be used in othe math functions. If a variable is wished to be used this way, the variable name may not be a string. Using the PRINT command, we can return the value of the varible as output. We do this by using the PRINT command followed by the variable name. There are not quotations around the variable name, however, PRINT may use both quotation text and variables in the same line.
10 INPUT "This is a number variable"; VariableNumber variables may be used as any other numbers simply by placing the variable name where the number would normally be.
10 REM assume varible ONE and Variable TWO are fiveThe other variable that may be used in conjunction with INPUT, are string variables. String variables are used in much the same way as numbers, however, strings can contain letters and spaces as well as numbers. Strings cannot do mathmatic operations (although strings can become numbers as discussed in later lessons). All string variable names must end in the $ sign.
10 PRINT string$The rules of text with the INPUT statment are much the same as with PRINT, although use of commas to tabe over or lines of text separated by variables do not work. Also, in Basic, each input statment will return a ? at the end of any text line, or even if no text is used.
10 INPUT "When displayed, there would be a question mark at the end of the line." ;variablePRINT can also be used to print variables. This will be discussed in the chapter on INPUT statements. However, It should be known that PRINT can be used on the same line to print text, variables, and more text as follows.
10 PRINT "Text can go here " variable " with a variable in the middle, or vice versa, or in any combination"Thats all for this lesson, however, be sure to check back for more. In the mean time, write a program using INPUT. Example 1: write a program that asks the age and name of a person, and then displays it. Example 2: write a program that asks for a persons name and phone number.
QBasic Homeianmacallen.com | Annex | Archive
All content Copyright 2006 Ian MacAllen Unless otherwise Atrributed.
Contact:
ianmac47@hotmail.com