home *** CD-ROM | disk | FTP | other *** search
- -----
- INPUT Statement
-
- The |INPUT~ statement allows you to input from the keyboard while the
- program is running. When the computer comes to an INPUT statement, the program
- stops, displays a question mark, and waits until you enter a number, then it
- continues with the next line. After the word INPUT you need to place a
- variable.
-
- example: 10 INPUT X
-
- You can place a |prompt~ (words, in quotes, to remind you what to
- enter) between the word INPUT and the variable. If a semi-colon follows the
- prompt, then a question mark will be displayed after it. If a comma follows
- the prompt, then no question mark will be displayed.
- -----
- INPUT Statement (continued)
-
- This is what an INPUT statement might look like in a program.
-
- |10 INPUT "What is X equal to";X~
- |20 PRINT X;"+ 3 =";X+3~
-
- Try typing in this program, running it and watch what happens. After
- you do that, change the semi-colon in line |10~ to a comma and |RUN~ it. To
- execute the program again for a different variable value, type |RUN~ and put in a
- different number when the computer asks for X.
- -----
- String variables
-
- Variables can represent letters and text as well as numbers. A
- variable representing a string of letters is called a |string variable~.
-
- String variables are written like |numeric~ variables with a trailing
- dollar sign.
-
- example: |XYZ$~="Greetings from sensible software!"
-
- You can input a string variable just like you did a numeric variable.
- Try running this sample program.
-
- |10 INPUT "What is your name";N$~
- |20 PRINT "It's nice to meet you ";N$;", I'm the IBM Personal Computer."~
- -----
- More on the LET Statement
-
- Now that you can input and output from the computer, let's really make
- the computer do something. Mathematical calculations can be performed in BASIC
- with the LET statement you were introduced to in lesson one. The LET statement
- will set a variable equal to some numeric expression. Here are the basic
- |arithmetic operators~ and how they are handled in BASIC.
-
- FORM DESCRIPTION EXAMPLES
- |+~ addition A|+~B 6|+~12
- |-~ subtraction A|-~B 23|-~7
- |*~ multiplication A|*~B 3|*~(2-1)
- |/~ division A|/~B (8+2)|/~4
- |^~ exponentiation A|^~B (5*3)|^~2
- -----
- More on LET (continued)
-
- Here are two specific examples of the LET statement.
-
- CELSIUS TO FAHRENHEIT CONVERSION
-
- |10 LET F=1.8*C+32~
-
- YEARLY INTEREST
-
- |10 INTEREST=PRINCIPLE*RATE~
-
- Try writing a program that lets you input a Celsius temperature and
- have the computer convert it to Fahrenheit and PRINT the result. (Use the
- |INPUT~, |LET~ and |PRINT~ statements.) Remember, the IBM version of BASIC allows
- you to omit the word LET if you wish.
- -----
- More LET (continued)
-
- Here is one way to write the previous program.
-
- |10 INPUT "Enter the Celsius temperature.",C~
- |20 F=1.8*C+32~
- |30 PRINT F;"Fahrenheit equals";C;"Celsius."~
- -----
- SAVE Command
-
- You can |SAVE~ a program on a diskette with the SAVE command. This
- will save your program so that you can retrieve and run it again. You must
- have a diskette ready for use to use this command (you can SAVE a few programs
- on the BASIC Prof diskette, but you should use a different diskette for large
- programs.)
-
- To SAVE a program, type |SAVE"name"~. The |name~ can be anything you wish,
- but must be eight or less characters with no blank spaces.
-
- |Invalid characters are~
-
- |+ = : ; , . ?~
-
- Type in the following program. SAVE it with the name "INTEREST" by
- typing |SAVE"INTEREST"~.
-
- |10 INPUT "Enter the amount of principle.",PRIN~
- |20 INPUT "What is the interest rate (use decimal)";RATE~
- |30 INTEREST=PRIN*RATE~
- |40 PRINT "$";INTEREST;"on $";PRIN;"at";RATE;"%"~
- ------
- LOAD Command
-
- The |LOAD~ command retrieves a program from the diskette and |loads~ it
- into the computer's memory. Hopefully you were able to SAVE your program from
- the previous page. The next time you want to use it, type |LOAD"name"~ (in
- this case |name~ is |INTEREST~). Typing LIST will print the program on the screen.
-
- Try the |LOAD~ command now and |LIST~ the program.
- ------
- NEW Command
-
- The |NEW~ command |deletes~ the program that is currently in memory.
- It will also clears all variables. When you want to begin writing a new
- program, you need to clear any old program remaining in the computer's memory.
- Otherwise, you may get lines from the old program mixed in with lines from the
- new program.
-
- The format for the NEW command is simply type NEW and press return.
- Try out the NEW command by typing |LOAD"INTEREST"~, press return and |LIST~
- the program. Now type |NEW~ and press return and try to |LIST~ the program
- again. This will |not~ erase the program from the |diskette~, |only~ from the
- computer's |memory~.
- -----
- End of Lesson Two
-
- One more lesson finished. These first two lessons are the foundation
- for the rest that you will learn. From this point on, programming really
- starts getting fun. By the end of the next lesson you should be able to write
- your own simple games, but only if you understand everything covered so far.
- If you don't really understand about variables or the INPUT statement now,
- review the first two lessons before you continue with lesson three.
-
- If you are using the BASIC Prof, |The PC-Prof.~
- let me know who you are! Send your name |P.O. Box 26~
- and address to: |Salina, Kansas~
- |67402-0026~
-
- If you like the Prof, include a contribution ($30 - $50 suggested) to
- help support development of additional volumes. Please copy and share the
- Prof. with other IBM P.C. users.
- -----
-