DogAndPanda: computerc64manual.htm

computerc64manual.htm

LIST!::::::
Academy on Computers
HANDS-ON
COMMODORE 64
A BEGINNER'S
MANUAL
WNET/THIRTEEN RO. Box813 New York, NY 10101
This manual is part of the Academy on Computers, a self-directed learning activity. The Academy is based on the Bits and Bytes programs produced by the TVOntario network and presented in the United States by WNET/THIRTEEN.
Project Team in Canada:
Project Officer: Judy Winestone
Editor:                  Mei-Lin Cheung
Designers:           Danny Leung/Roswita Busskamp
Photographer: Garth Scheuer
This hands-on manual follows the model developed by Trudy Van Buskirk for other microcomputers used in The Computer Academy. The adaptation for the COMMODORE 64 was made with the assistance of David Sideris.
Project Team in United States:
Director:                                                                   Carol L. Angert
Supervisor of Academy Services:                            Peggy Yalman
Supervisor of Station Relations:                                Lois Dino
Project Assistant:                                                     Denise O'Connor
WNET Administrative Staff
Director of Educational Programs:                           Shirley B. Gillette
Senior Manager of Educational Programs:               Debbi Bilowit
Publications Supervisor:                                          Melinda Klaber
Manager of Systems Analysis:                                 Ian Coles
Vice President and Director, Education Division: Stephen L. Salyer
Academy on Computers is presented in the United States by the Education Division of WNET/THIRTEEN.
Academy on Computers was conceived, developed, and produced by TV-Ontario, Canada's leading educational television service.
AA TVOntario
ORDERING INFORMATION
For more information, please write to: Academy on Computers WNET/THIRTEEN PO. Box 813 NewYork, NY 10101
©Copyright 1983 by the Ontario Educational Communications Authority. All rights reserved. No part of this book may be reproduced in any form without permission in writing from the publisher. Reproducing passages from this book by mimeographing or by photographic, electrostatic or mechanical means without the written permission of the publisher is an infringement of copyright law.
Printed in the United States.
Logo Design: Juanita Gordon
I TABLE OF CONTENTS
Before You Begin...............,.............. 4
Unit I:         How Do You Start?................... 6
Unit II: How to Use Ready-Made Programs......14
Unit III: Programming — Who Me?.............18
Unit IV: Programming in BASIC (1).............22
Unit V: Programming in BASIC (2).............28
Unit VI: How to Modify a Program..............33
Troubleshooting.................|.............37
Explanation of Error Messages...................37
Glossary......................'.............38
NOTE:
Many people write computer programs that they are happy to give away free. There are thousands of them freely circulating in user groups, by mail, or in newsletters. Some of these programs are very good indeed, some are small and simple, and some don't work.
Commercial programs, on the other hand, are designed for sale. They are professionally written, often large and powerful, and they come with good documentation. When you pay for a product, you expect to get more, and in the field of computers you usually do.
It's often possible for an individual to make copies of a commercial program to give or sell to others. This is called piracy; it's highly unethical. The user receiving the pirate copy will lose on documentation and support; the pirate is liable to be sued; and the commercial program house may give up producing and selling programs that are pirated. We all lose. Remember that in all cases the onus is on the person making a copy of a program to ensure that copyright interests are not being violated.
i BEFORE YOU BEGIN
INTRODUCTION
This book is intended to be used in a hands-on experience with a COMMODORE 64 computer. It introduces you to the machine and takes you step by step through a variety of activities designed to increase your understanding and command of the COMMODORE 64. It does not presume any prior knowledge of computers, and avoids jargon wherever possible.
As you will discover in going through the book, there is no magic in learning how to operate a microcomputer. There are, however, a couple of strategies that will make your learning experience more successful: do work through all of the suggested activities, and be patient with yourself. For many of you, this is probably a very new kind of experience and it may take you a while to catch on. When you do, though, we think you'll find that computers can be a lot of fun!
We also hope that this book and your hands-on experience will aid you in evaluating the role of microcomputers in society. In a world where most of us encounter a computer in some form almost everyday, it's important that we all have at least an elementary grasp of what computers are and what they can and cannot do.
OBJECTIVES OF THE HANDS-ON MATERIALS
When you have finished working through the hands-on materials, you should be able to:
•   operate the COMMODORE 64 and disk drive;
•   load and run programs from disks;
•  save and copy software;
•   use the computer as a calculator;
•  write short programs using BASIC commands; and
•   modify BASIC programs.
This manual is only a beginning. Once you are comfortable with the COMMODORE 64, you can quickly and easily master the operation of other microcomputers simply by reading the operation instructions that accompany the hardware. Microcomputers do not differ markedly from one another, and you are learning about features that are common to them all.
WHAT YOU NEED TO GET STARTED
Hardware:
You need a COMMODORE 64 computer and one VIC-1541 disk drive. You will also need a display of some sort — either a standard TV or video monitor (black-and-white or color). A color monitor will allow you to take advantage of the excellent color and graphics capability of the COMMODORE 64.
Software:
In addition to the diskette that accompanies this manual, you will need one blank 51/4-inch diskette. Diskettes (also called "disks" or "floppy disks") are available wherever computers are sold.
4
Time:
Each of the six units in this manual will take approximately 60 minutes to complete. Although you are free to work through the activities at your own pace, you will learn more and work more effectively if you spread the work evenly over the duration of the Academy. Remember: you are in charge of the learning — not the computer. Don't hesitate to stop if you become tired or frustrated.
THE BOOK ITSELF
Units I and II introduce you to the COMMODORE 64 keyboard. You will learn what each of the keys does and how to correct typing errors. You will also learn how to load, run, copy, and save ready-made programs.
Unit III shows you how to use the computer as a calculator and how to list the program on the sample diskette.
Units IV and V teach you elementary programming in BASIC — not enough for you to write a very useful program, but enough for you to understand what programming is and to go on to more advanced texts and courses, if you wish.
Unit VI explains how to modify existing programs to suit your own needs.
The section entitled "Troubleshooting" identifies some of the more common programming errors and explains how to clear the screen, stop a program, start again, etc.
The Glossary contains explanations of many of the technical terms used in this manual. In the text, we have tried to keep these to a minimum, and to explain them as we go along.
I UNIT I
HOW DO YOU START?
Let's begin this first hands-on session in a very methodical way.
The COMMODORE 64 system consists of at least three separate components: the keyboard, display unit, and a disk drive.
If you are using a TV or the video monitor, it will be connected to the computer by a cable. Make sure that both the computer and the monitor are plugged into an electrical outlet. Make sure that there are no diskettes in the disk drive.
Turn on the monitor; then, turn on the disk drive and then the computer. The on/off switch is located on the right-hand side of the computer and at the rear of the disk drive.
When you turn on the COMMODORE 64 the following message appears on the screen:
This message tells you how many "bytes" of memory are available for BASIC programming. A "byte" is roughly equal to a character (letter, number or symbol).
The flashing square that appears under the word READY is called the "cursor," and its presence indicates that the computer is waiting for you. It's your turn to do something.
6
You may want to adjust the brightness and contrast of the screen to make the message easier to read. On the COMMODORE 64 video monitor, the brightness and contrast controls are to the lower front of the monitor.
THE KEYBOARD
■■J GJ3 CSJ m.'i-m fejj iZJ trrl i'"i fc5l 4"J ••';# ■ I M 17^1 l-'-l ■■ ■■ ^m mZM
iCaii 1O1 lOj (Oi iDj iOj iOj lO) lO) tQi iDi iOi iOi lOj iCSlj ■ iOi
■■■P 1':' 1 wi^m liJ FFl M.'il IJT1 M-Vl 1=^1 l»Til FTSl PI lrr=l W BM ^M O
i@i l@l iSl |S| tSi iSi iBi iQi |Q| iSi iSl iSl tSl iSl faaii ■ iSi
■■fl ■■ »r| ■ M- ■ Ej FFi t«i^i ■■7TB m ra nrsB ■■ ■■ ■■ ■■■■p b^bm ils
ISl fib i^lPlilii^i^i^i^i&iiSilSII iSilS) i§i HiSl
The keyboard is like a standard typewriter, with keys of several types.
The alphabetic and numeric keys are arranged in a pattern similar to that found on most typewriters. It is known as a QWERTY keyboard, the word QWERTY referring to the first six keys (from left to right) in the second row from the top.
ALPHABET KEYS
With the COMMODORE 64 you can type all upper-case letters, all lower-case letters or a combination of both. When you first turn on the computer, you are automatically in the "Upper-case/Graphics" mode, which means you can type upper-case letters and more than 60 graphics you see on the keys. There are two graphics on each key. To get the graphic on the right side, simply hold down the ETTraa key and type the key with the graphic you want. In this way, you can type upper-case letters and graphics at the same time. You can create pictures, charts and designs by placing characters side by side or on top of each other (like building blocks).
To switch into the "Upper-/Lower-case" mode (i.e., to type lower-case characters on the screen), press the Q key and the EUSl key simultaneously. To return to the "Upper-case/Graphics" mode from the "Upper-/Lower-case" mode, simply press the Q key and EH5B key again. In other words, to switch from ^Upper­case/Graphics" mode into "Upper-/Lower-case" mode and vice versa, always press the Q key and EUSl key simul-
7
taneously. To capitalize letters while in the lower-case mode, press the gntiaM key just as you would on a standard typewriter.
NUMBER KEYS
The number keys are located on the top row of your computer keyboard. If you have previous typing experience, you need to be aware of two differences between this keyboard and some type­writer keyboards. With the computer, you cannot type the letter T' as the number xv1." Also, never substitute the letter "O" for a zero. The computer screen displays a zero with a line through it (©) so that you'll be able to distinguish it from the letter xxO."
PUNCTUATION AND SYMBOL KEYS
The computer keyboard has the punctuation and symbol keys which appear on a standard typewriter, as well as several others used in computer applications. To type any symbol which appears on the top of a key face, simply press the key. To type the bottom symbol, hold down the g^TTTU key and press the symbol key. Notice that certain punctuation marks and symbols also appear at the top of some keys. To type these symbols, hold down the key and press the relevant key.
SPECIAL KEYS_____
■3EB The KAW key is always used in conjunction with control another key to perform a command or function. For
example, try holding down the fSflEffi key while tapping each of the numeric keys from 1 to 8. If you are using a color monitor the color of the cursor will change to correspond to the color labelled under the numeric key you have pressed. Now, any characters that are displayed on the screen will appear in the selected color. If you are using a black and white monitor, obviously the color of the cursor will not change, but you will be able to detect a variation in the shadings as the cursor changes colors.
G3             The COMMODORE key Q , in conjunction with other
com- keys, also performs a variety of functions. If the key is modore held down while any of the alphabetic keys is pressed,
KEY
the symbol on the lower left of the alphabetic key will be displayed on the screen. When used with the numeric keys from 1 to 8, the Q key allows for the selection of eight additional text colors.
There are two EQEQI keys, one on each side of the keyboard. They both serve the same purpose. The gcMim keys work like those on a standard typewriter. Many keys are capable of displaying two letters or symbols and two graphic characters. In the "Upper-/ Lower-case"mode, the gTTTOa key gives you standard upper-case characters. In the nUpper-case/Graphic" mode, the gffim key will display the graphic character on the right side of the key. The Upper-case/Graphic mode is entered by pressing the gclSllsHi and Q keys simultaneously.
The SBBQ key "locks" the keyboard in the SHIFT
position, which allows you to continue typing in the upper­case or graphics mode. To "unlock" the keyboard, simply press the WTRJ key again.
8
EBBED The UiaiiMi key is used to register a command or
program statement into the memory of the computer, and to drop the cursor from one line to the next.
The I I key positions the cursor at the "home"
clear position of the screen, which is the upper-left corner.
HOME
When EQQl and uQZy are pressed simultaneously, the screen is cleared and the cursor is placed in the home position.
There are two keys marked »*-^™ , one with up and down arrows KIR , and the other with left and right arrows            IOB
CURSOR P?^5
keys iit*Sil . To move the cursor down and to the right you
use the cursor key only. Using the EEEDI key and the KH3B keys allows the cursor to be moved either up or to the left. The ES3I keys have a special repeat feature that keeps the cursor moving until you release the key.
The I I key is used to move the cursor back a space,
instant erasing the character to the left of the cursor. By pressing delete EHQDi and IflHl it allows you to insert information on
a line. It puts a space into a line of characters and allows you to type in a missing letter.
Normally, depressing the I-fffll key will stop the execu­tion of a BASIC program. It signals the computer to STOP doing something. Using the I-flffl key in the shifted
mode will allow you to automatically load a program from tape only.
IJJAfclsU IJJAMJJ operates like the name implies. It restores the computer to the normal state it was in before you changed things with a program or some command. (More about this later.)
The four function keys on the right side of the keyboard can be "programmed" to handle a variety of functions for repetitive operations. Function keys will be used with plug-in cartridges containing special programs, and in programming.
MATH OR OPERATION KEYS
The Math keys (or operation keys) are used to instruct the computer to add, subtract, multiply, divide, and raise a number to a power.
The symbols for addition, subtraction, and equals are the usual ones you're familiar with, but the multiplication and division symbols may be new to you.
O Addition O Subtraction O Multiplication O Division B Equals
9
Before you go on, have some fun with the keyboard. Fill the screen with characters. Try out all of the keys. Press them one by one: hold one key down longer and see what happens. Experiment with the gn?W , Q
and
keys.
Don't be afraid to play with the keyboard. That's what children do and they learn very quickly. Remember: you can't break a computer unless you physically drop or throw it — something you may want to do before you have finished working through this manual!
IIYDHOJF Jl JFURJFJFIF1RKRKFFLF0RKFKFIRKRK DIC03FJFriRM0413U3?37URJFJFrFLDLD:D.Di.Cr CKE1E M848484UTJK6KFLF949301SLDS: LD09393 93ICKRKKF]FKFK049494940RL64d3«PD0RITK6KC KIRITIGKKGKGKGK6IFIEK0LOLD0EOE1KDKDILFOI EIJKKDL00E0EIRKKFKF0IEI438383UEJDUF747UE 3DJFJFKFKFKFJFJFJFJFJFJEU37M37374377FVET 35E7R84849485*5»PVeveH,H/H*H HPYOLGKBJRH YE7HDHHFNCMHFGDFSRMEQICERRTFGFYIHGU6JHIJ KJOUIHKJLHKWMN.rWM.II,BHUNItX/X.HJGHGDEVE JDHDNUMDJJEWMrCHCr«FJHRVUTJUIl('746347JDJ DHDHDYEJDJDJDJHFHFHEYY28RURUIFKFKFJUJGUT 775UFKFKUKUKJI8IFKKi938484UFJF84UJJKUICFl K8R1RIIRIIJDJEURIRKFFURUKKF0R848EIIEII19 3848FKFKI48RIFKFRI8I4KRKFIF8RIKR0R0KKFICI R747RI1GITIGK6KRI8873S4G5758ITIK6J6HDHDI DDGXGHFHF JFJ28F JRYD6EYDJFHGHGJGIUT85 I4H 849RO0ROGITmOIT95IOTI6JJNUMHBM8.HMMNyB CBDHDHFYEJDKCMCHC J JJ J JJYYTRRDVBNJ6987G65 4R378IUYHGTRFDEGBVFDDCXVUTHHJM.. ./;»?-♦ 890LL . ..nJUIJJU76545DTHGCUCN0re,BNBNUH CVDHCNCIICmiUR7EJCJJQRUR06SFDDVEHD)CUFJCV jrURJFJFHDTUGSGSJDEHDJSKSJSHDVEHSJSKOHDV UNSHSJSJDJDHDVENDJDKUUUJSKAQQSJSICSJDHDEH DJSJSKSKDJDJCNCHDV7USICXNCNCV0HCnCKRlEUUi
When you have completely filled the screen with characters, count the number of characters and spaces in a single line and then the number of rows on the screen.
There should be 40 characters (including spaces) across and 25 rows down. These are the maximum dimensions of the screen. If you are typing or drawing pictures on the screen, you have a maximum 40 x 25 "grid" on which to work.
If you wish to clear the screen, either
1. Turn off the computer. Wait several moments and turn it on again. You will see this:                        _____^
This clears the screen, and empties the computer's memory.
Or
2. Hold down the | | key and press see the following:
You will
10
By pressing yŁQ and ■:j**w:i^ , you have not only cleared the screen, but have also restored all the normal modes of the computer (i.e., Upper-case/Graphics, light-blue cursor color). This method, however, does not empty the computer's memory.
3. Hold down the KU1UUI key and press the | | key. This
is what you will see:
This method clears the screen and sends the cursor back to the "home" position, but it does not empty the computer's memory.
HOW TO CORRECT TYPING ERRORS
Typing errors are much easier to correct on a COMMODORE 64 than on a regular typewriter. Try this:
1. Press G3 and EBEDI to switch to vxUpper-/Lower-case" mode and type Thus is a Commdore 64 Commputer.
Your task is to change Thus to This, Commdore to Commodore, and Commputer to Computer.
Let's begin with Commputer.
2.     Use the ■asn*» and the cursor control keys ( ) to position the cursor over the second m.
3.     Press the |fiH| key. The word Computer should now be spelled correctly.
To change Commdore to Commodore,
4.     Use the EQSB and the cursor control keys ( M ) to position the cursor to the right of the
second m. ^^^^ 5. Hold down the TSSSM key and press Kgl . Notice
11
that all of the other characters in the line moved over one space to make room for the new letter.
6.    Type o to complete the word Commodore.
To change Thus to This,
7.     Use the »^:iiaa and cursor control keys ( ) to position the cursor over the u.
8.    Type i. The word This should now be correct.
What if you wanted to change a Commodore 64 Computer to a Commodore Computer"?
9.     Position the cursor one place to the right of the 4 in Commodore 64.
10.   Press the B I key three times. The phrase should now
be correct.
A SAMPLE PROGRAM
Now that you know what the keyboard is all about and how to correct typing errors, try typing this short program.
1. First, clear the screen and restore "Upper-case/Graphics'' mode by pressing I I and f;l^W«!IJ . Then type NEW
and press iskwshi .
2.    Type 10 PRINT "HELLO, I AM YOUR NEW COMMODORE 64"
3.    Check your typing. Make sure that you have copied the line exactly, including the quotation marks.
4.    When you are satisfied that the line is correct, press
5.    Type 20 PRINT UWHAT IS YOUR NAME?"
6.    Check your typing and then press nanism .
7.    Type 30 INPUT A$                    ______
Check your typing; then press m*m;m .
8.    Type 40 PRINT A$                               ______
Again, check your typing; then press f-TSIfl-iyi .
9.    Type 50 GOTO 40 and press m*hkim .
10.  Type 60 END and press hUMM .
11.  Type RUN and press MiUhlJl . You will see this on the screen:
18 PRINT "HELLO, I AM VOUR HEM COMMODORE
28 PRIHT "WHAT IS VOUR HAME?" 36 IHPUT AS 46 PRIHT AS 56 GOTO 46 86 EHD
HELLO, I AM VOUR HEM COMMODORE 64. WHAT tS VOUR HAME?
12
12.  Type your name and then press iu*m;i:i .
13.  To stop the program, turn off the machine. (In the next unit you will learn how to stop a program without having to turn off the machine.)
If an error message — SYNTAX ERROR or ILLEGAL QUANTITY, for example — appears on the screen, you can be fairly sure that you have made a typing error. Type NEW and then press iiwusm ; then retype the program.
SUMMARY
The COMMODORE 64 keyboard consists of both alphabetic and number keys, as well as ''special" keys such as maa , Q , II J! , i;»»imm , and m=*m;m . There
are also two cursor control keys ( H3JS , H-Mfl ) that allow
you to position the cursor anywhere on the screen.
The maximum dimensions of the screen are 40 characters by 25 rows. There are two display modes that can be used: "Upper­case/Graphics" mode and "Upper-/Lower-case" mode. The modes are switched using Q and
There are three ways to clear the screen: (1) by turning the computer off and on again (this empties the computer's memory and calls up the COMMODORE logo), (2) by pressing | | and
or, (3) by pressing EHEM and
13
1 UNIT II
HOW TO USE READY-MADE PROGRAMS
NOTE: To complete the hands-on activities in this unit, you will need the diskette that accompanies this manual, and a blank 5V4-inch diskette. Also, make certain that the computer is in nUpper-case/Graphics" mode for all further activities.
LOADING READY-MADE PROGRAMS
1.  Take the diskette that accompanies this manual out of its envelope. Be careful not to put your fingers on the oval cutout, where the brown material is exposed. Information is stored there, and heat or grease from your fingers could damage it. As an added precaution, hold the diskette by its label.
2.  Open the door of the disk drive by pushing it in and carefully slide the diskette into the drive. (Check that the label is up and the oval cutout is positioned to enter the drive first.) Close the door of the disk drive.
3.  Type LOADu$",8 and press IslitfhlSl . This accomplishes two things: first, it starts the disk drive; and second, it tells the computer to "load" the names of the programs on the diskette into its memory.
4.  Type LIST and press (3S!EE) to display the names of the programs on the diskette.
5.  To load the program titled SELFTEST, type LOAD USELFTEST",8 and press l;mil;l?l .
The command LOAD tells the computer to search for the program and copy it into memory. The program is still on the diskette, but when you see the word READY on the screen, it is also in the computer's memory.
Sometimes you may get an error message when you try to load a program, indicated by a flashing red light on the disk drive. This usually means that you have made a spelling or typing error. Be sure to copy the title of the program exactly as it appears in the list of program names (called the "disk directory"). And don't forget to put quotation marks around the title of the program.
If you continue to have difficulty loading the program, ask a technician for help. Beginners often blame themselves when things don't work out as they should, but sometimes it's the diskette or the disk drive that is to blame.
14
HOW TO RUN THE PROGRAM NOW IN MEMORY
1. To run the SELFTEST program now in memory, type RUN and press l;l^dl;l?l .
The SELFTEST program is a computer version of the self-tests that appear in the Academy on Computers Resource Book. We think you'll find the computer version much more interesting than the printed self-tests, and we encourage you to use the SELFTEST program on a regular basis.
2. Before going on, work through Self-test 1, "Getting Started/' based on Chapter 1 in Bits and Bytes. When you've finished the test, read the next section of this manual which explains how to stop a program.
HOW TO STOP A PROGRAM - OR, "I DON'T WANT TO RUN THIS ANYMORE"
For any number of reasons, you may want to stop a program in the middle of its run. Perhaps you've forgotten the instructions and want to go back to the beginning; perhaps you're tired and want to quit; or perhaps you're just ready to go on to something new.
1. To stop a program in the middle of its run, press the key.                                                _______________
only two v»iu»s (1
Prcsc <RCTUM> to contii fcrMfc in It
Each instruction or "line" in a program has a number that identifies it. In the example above, we stopped the program at line 62. The number you see on the screen will probably be different, depending on when you pressed the I-WI I key.
At this point, you have three choices: (1) to continue from where you left off; (2) to start again from the beginning; or (3) to clear the program from the computer's memory.
1.  To continue from where you left off, type CONT and press
QUEUED
2.  To start again from the beginning, type RUN and press
15
3. to clear the program from the computer's memory, type NEW and press QUED . Then press Eff-1 to clear the
screen.
With many commercial programs, it is not possible to "break in." Programmers can write programs that disable the EfflJI keY>
i.e., make it nonfunctioning. This tactic is especially common in writing educational programs for young children. But for users young and old, it is extremely frustrating, when working on a set of questions, to hit the 1-ffflM key accidentally, and have to start
Km
all over again.
HOW TO SAVE PROGRAMS
Many computer operators like to make second or "duplicate" copies of software programs, in the event that the first is destroyed or damaged. You should know that computer programs, like all other forms of "intellectual property" (e.g., books and articles, recorded music, videotapes, etc.) are protected by copyright. You are not permitted to copy programs without first obtaining permission from the copyright holder. In some cases, you may also be required to pay a fee.
The program that you are going to copy and save in the following exercise is the property of the Ontario Educational Communications Authority, which grants you permission to copy the program for your own use.
NOTE: To complete this exercise you will need a blank 51/4-inch diskette, in addition to the diskette that accompanies this manual.
FORMATTING A DISKETTE
In order to save a program on a blank diskette, you must first format the disk.
1.   Put your blank 51/4-inch diskette into the drive and close the door.
2.  Type OPEN 1,8,15,"NEW0:TEST DISK.TD" and press liliillilil . The disk drive should now run for approximately 85 seconds.
3.  When the disk drive stops running, remove the diskette.
4.  Type NEW and press uaiLLLJ to clear the computer's memory.
5.   Put the diskette that accompanies this manual into the disk drive and close the door.                    ______
6.  Type LOAD"SELFTEST",8 and press LIMLU)
7.  When the word READY appears on the screen, replace the diskette with your blank diskette.
8.  TypeSAVE"SELFTEST",8 and press GHEEE) . When the computer has finished saving the SELFTEST, the cursor will appear on the screen.
16
VERIFYING THAT YOU HAVE SAVED A PROGRAM
1.  Type LOAD"$",8 and press (JMLUJ to load the directory.
2.  Type LIST and press (33JJBB) to display the directory. If the name of the program appears in the directory, you can be fairly sure that you have saved the program correctly. (Notice that the "name" of the diskette is TEST DISK. Compare this line (called the "disk header") with the command used to format the diskette in the previous exercise.)
3.  Type NEW and press hmihKl .
4.  Type LOAD"SELFTEST",8 and press lilMilil
5.  When the word READY appears on the screen, type RUN and press QSQEED • If the program doesn't appear on the screen, repeat the entire process. Don't be discouraged if, at first, you make some mistakes. If need be, ask someone for help.
6.  When you are ready to stop, remove the diskette from the disk drive and turn off the unit.
7.  Turn off the computer and the display unit.
NOTE: Always remove any diskettes from the disk drive before turning the unit off.
SUMMARY
To check the names of the programs on a diskette, type LOAD>v$",8 and press UliiLLlil • Then, type LIST and press L-mihMI to display the disk directory. To load a program into the computer's memory, type LOAD'NAME OF PROGRAM",8and press U3*'u:i .
To run a program, type RUN and press GByBEC) To stop a program in the middle of its run, press EJZI .
To clear a program from the computer's memory, type NEW and press IdAilhHI .
To copy programs onto a blank diskette, you must first format the diskette. Then you can use the command SAVE. Remember: It is illegal to save and copy programs without first obtaining the permission of the copyright holder.
17
I UNIT III PROGRAMMING - WHO ME?
•undamentally, programming is problem solving. You can program i computer to calculate your income tax, turn off your oven at a specified time, or determine the best route between Toronto and New York.
In solving any problem, you need to think about the steps that must be taken in order to reach a solution and about the order of those steps. Computers cannot help you with this. But once the steps have been identified, computers can help you with the solutions. However, computers need very precise and specific instructions, written in a code or language they can understand. This is what is meant by programming.
Of course, you don't have to become a programmer in order to operate a computer. Higher-level languages and new develop­ments in hardware and software have democratized computer access. The majority of users now spend most of their time running ready-made programs. For most of us, it is enough that we can tell the computer how to do the things we want it to do.
USING THE COMPUTER AS A CALCULATOR
Any computer can be used as a calculator. Of course, if this were all it could do, it would be a very expensive calculator. But you have already seen evidence of some of the computer's other capabilities.
When you use a computer as a calculator, you are engaged in programming; that is, you give the computer a set of instructions which it carries out sequentially in order to solve a problem.
NOTE: In the activities that follow, remember that the ((D) is different from the letter (0), and that the number one (1) is different from the letter (I).
1.  Type PRINT 2 + 7 and press UiaiLUiJ
2.  Type PRINT 4+ 7-2 and press EBBED .
3.  Type PRINT 25/5 and press l;l=mhl?l .
4.  Type PRINT 10*3 and press iiHiWM .
A word about mathematical notation: While the + and - are quite straightforward, the * and / represent multiplication and division, respectively. Note that you do not type = at the end of a problem.
The question mark is another form of the BASIC command PRINT.
18
1.   Type ?(2 + 3)*4-2 and press IzmihHI
2.   Type PRINT (2 + 3)M-2 and press 1:1^11:1*1 .
The answer to both problems is 18, since ? and PRINT mean the same thing.
The computer performs arithmetic functions in the following order: (1) brackets, (2) multiplication or division (whichever comes first), and (3) addition or subtraction (whichever comes first).
1. Press i^!llal and RTI to clear the screen.
2.   Type ?(2 + 3)*4-2 and press i:i*w:m
3.   Type ?2 + 3*(4-2) and press ustni;m
4.   Type ?2 + (3*4)-2 and press hmUsHI
Is this what you see on the screen?
Using a programming command (? or PRINT) to do arithmetic is called "immediate execution" mode. This means that the computer executes the command right away. It doesn't have to go through any other instructions before it prints the answer, the way it does in a program.
1. Type
?2 + 3M/6*(12 + 6)-(13*2) + 6/1Q+5-4/3*(10*10)*15 + 25 and press (HIDED
Is your answer -1957.4? If it isn't, check your typing.
Before going on, try some arithmetic problems of your own. Remember: type ? first, and don't use = . Simply press mannm when you want the answer.
WHAT DOES A "BASIC" PROGRAM LOOK LIKE?
1.   Put the diskette that accompanies this manual into the disk drive.
2.   Load the program called SELFTEST: type LOADuSELFTEST",8 and press (JiiLLlil .
19
Then, type LIST and press uiaiiUUJ • Numbers, words, and symbols will begin to scroll on the screen. This is a "listing" of the program. When the program has reached the end, the cursor will appear on the screen.
Mrto be usrD'u •• ,n,° r"t"""'n ■■ -
Hiiytes**"" CG',JU,,CT10,, MITH THE iit«
18841 A$=A$»" TELEUISION SERIES AND «ŁS OURCE I00K. " 60SUB18849
18842 A$ = "(C) -0PVR16HT 1983 BV I HE r*T«
S ♦UTHORITV "
18644 A$ = A$V                     «LL RI6HTS RESERV
ED." G0SUB18849 PRINT
18845   A$ = ">t06RArtfIlf6 TEAM: "60SUB18849: f* ft IN T PR f HT*T** *
-E80RAH LEW. MLTON UAN DEI TETER WARDER XEEH, MJDV OIM
18846   a$ = "
eItoSe          ~iet"              *""' mji>v °"
18847  g0sub18849-print"h
18848   forx 1 to 1588 next got09
18849   rORX=lTOLEH<A$>PRINTMD$<A$,X,l>'
You can also slow down the speed of the scrolling or stop the listing as it is scrolling on the screen.
4.  Type LIST and press QSQEQ .
5.   Hold down the KSI-ffi key and you will notice that the scrolling slows down.
6.   Press ERJI ■ You will see a "BREAK" message at the line
where you stopped.
4T5 Q*Q»1 A$ = MD$(Ai$<A(I)>/2)A$="'"♦CH 3i(ASC<Ai$<A(I>>>0R^28>♦A$V",,
88 60SUB38PRIHT PRINTTAB(9>"IS THE CDR RECT ANSWER." PRINT 485 G0SUB75 PRINT 60SUB68:60T0188 588 G0SUB58 READTS.HS
585 L = 14 G0SUB78PRINTTAB<9)"a!iaL<|> I RU I OR <-> -ALSE$":60SUB75 §18 PRINTSPCm'WUCT AND PRESS <„~| r-
fiji'pRIHT"<t> tC0RE"TAB<32>"<\> \EUHKT
THENSC=8 G0T0288
523 IFI=-2THENF=3G0T0688
525 Q = Q*1 IF<I = 1AN0TS=*,T,,)0R(I=2ANDT$=*'F
"*) THfMR'R+I
538 L=14 G0SUB78 IFI=1ANDT$="T"THENA$="|
l«i»-%IJI'" VT'S TRUE.":G0T0558 535 IFt=2AN[>TS=7,F"THENft$ = "r^'-- w»ll|!!
• »T'S FALSE," G0T0545
You can also choose to list any section of the program.
7. Type LIST 505-600 and press IzBdhKI .
585 1*14 G0SUB78 PRIIITTAB(9J',a!l!Eq> ]V0
I OR <-> -ALSE^' G0SUB75          ^^
5li PRINTSPC(7T"i*ELECT AND PRESS <_-| *.
5 PR INT "<f) fCORE"TAB<32>"<\> \FUHI*CE
rTTjcmn" printtabu8>,                  «™«"^
528R5VWMS" K$-"TF" GOsOBie KS = "" IFI=i THENSOO G0T0288 523 IFI= ?THENF=3 60T0G88 525 Q = Q»1 IF<I=iAHDTS="T">OR(I-?ANDTS= 'F ">THEHR;R»1
538 L14 G0SUB78 IF I = iANDTS--"T'IMŁNA$ "| ]♦[# _%I if'* ' nT'S TRUE." G0T0556 535 IF I 2AHDT$ = *F"IHENA$ = "»V-- -> I II " ' »T S FALSE," G0T0545
548 AS~"/0, THAT'S TRUE," IFI 1THIHAS "/ 8, THAT S FALSE."
545 G0SU838 PRINT AS HS G0SU888 PRINT GO SU875 PRIHT-j;" G0SUB68 G0T0I8B 558 PRINT"JL,*y G0SUB38 PRINT",-;" G0SUB75 P RIHT"J," G05TJB68 G0T0188 688 irF=8THENRE«DSC G0T0288
Look carefully at the lines on the screen. Notice that the lines are numbered sequentially (e.g., 505, 510, 515, 520, etc.). You'll see words like PRINT, GOTO, REM, FOR, NEXT, etc. These are BASIC commands. In the next unit, we'll look more closely at some of these.
20
SUMMARY
A program is a set of instructions that tells the computer how to solve a specific problem. Programs are written in computer languages — artificial languages that have their own vocabularies and syntax. BASIC is the language used by most microcomputers.
To see what a computer program looks like, type LIST and press I;UM;U1 . You can slow down the listing by holding down the ■mi key. You can stop a listing at any time by pressing
E 9
. You can also ask the computer to list specific sections
or lines.
21
i UNIT IV
PROGRAMMING IN BASIC (1)
CHARACTERISTICS OF BASIC PROGRAMS
All BASIC programs share the following characteristics:
•  They are made up of lines called "statements."
•   Each statement begins with a number.
•  There is always an END statement.
List the program titled SELFTEST. If you've forgotten how to do this, refer to Unit III.
Notice that the lines in the program are not numbered consecutively (180, 101, 102, 103, etc.). The reason is that it's much easier to modify a program later if you leave room to insert new lines. It is traditional to space the lines in a program 10 numbers apart (100, 110, 120, 130, etc.).
GIVING THE COMMODORE 64 INSTRUCTIONS
A BASIC program is a set of instructions that tells the computer to do something. These instructions fall into two distinct categories: program commands and system commands.
System commands — for example, LIST, RUN, NEW, — tell the computer to do something to or with a program.
Program commands — for example, PRINT, GOTO, FOR . . . NEXT — appear only within the context of a program.
PRINT
The PRINT statement is simple enough to understand, but powerful enough to enable the computer to execute complex arithmetic operations.
1.  Type NEW and press GEEED ■ ^^^
2.  Type 10 PRINT 4 + 4 and press!GHEED .
3.  Type 20 END and press M^HilJI .
In order to execute this short program, you need to use a system command.
4.  Type RUN and press izkhiski . You should see this:
The correct answer is 8. Notice that the cursor is flashing. This tells you that the computer has finished the program and is waiting for you to enter new information.
22
NOTE: We hope that by now using the GHEEE) key is second nature to you. From this point on, we will no longer remind you to press the UBIiiiUJ key after typing a command or statement.
In the next example, we have deliberately misspelled the word PRINT in line 10 in order to demonstrate how to correct errors in a program. Type:
10PRUNT4 + 4 20 END RUN
An error message will appear on the screen after you enter line number 10.                                                 ______
?SYATAX ERROR IK 18 READY.
The flashing cursor is the computer's way of telling you to retype the line. Type:
10PRINT4 + 4
Now, complete and RUN the program. Another way to correct the error:
1.  Type LIST 10 and press GHEEE .
2.   Use the cursor control keys to position the cursor over the U in 10PRUNT4 + 4andtypel.
3.   Press i:i*m:»i . The new, corrected version of the line replaces the old version of line 10.
Now, list the program and observe that the line has changed. The program should not contain any errors.
Try this. Type:
NEW
10 PRINT "4 + 3 = "
20 PRINT 4 + 3
30 END
RUN
In this program, lines 10 and 20 illustrate two different uses of the command PRINT. In line 10, it tells the computer to print on the screen whatever information appears within quotation marks. In line 20, it tells the computer to calculate the sum of 4 + 3. Notice that the main difference between the two lines is the quotation marks that appear in line 10.
NEW tells the computer to clear the screen first.
23
Here are a few more programs for you to try. Type NEW and press l-.mil:l?l. Then type:
1© PRINT "TWO TIMES SEVEN IS" 20 PRINT 2*7 3© END RUN
READY.
ij PRINT "TWO TIMES SEUEN IS" *8 PRINT 2»7 6 END
NEW
10 PRINT "***WOW*y
2© END
RUN
Type NEW and press QIIfliE) . Then type:
1© PRINT "*****" 20 PRINT"* 3© PRINT"*" 40 PRINT"*" 50 PRINT"* 6© PRINT "*****" 70 END RUN
i PRINT i PRINT i PRINT J PRINT 6 PRINT 6 PRINT f8 END RUN
To insert a line in the middle of this program, type:
25 PRINT"*" LIST
24
Notice that line 25 appears in the correct place in the numeric sequence, that is to say, between lines 20 and 30.
If, instead of inserting a line, you wanted to delete a line, you would type:
40 (press (JML12J) LIST
To delete any line from a program, simply type the line number without any information beside it.
No matter how you enter lines in a program, or add or delete lines, the computer always arranges them in the correct numeric sequence.
Try this. Type:
6 5?         "COMMODORE 64"
LIST
You'll see that the computer automatically closed the gap between the 6 and 5, and changed the ? to PRINT. The computer reformats programs according to certain conventions regarding spacing and wording.
VARIABLES
Memory is a collection of storage locations (similar to mailboxes), each with a unique address. In BASIC, a programmer can store information in a memory location without knowing or caring where that is. The information stored in a specific memory location can then be referred to by a symbolic name.
Information referenced in this way is known as a "variable" and the symbolic name is known as a "variable name." Variables are used to represent information (e.g., a word, a number, a name, an address) that the computer gets from the user in response to a question (e.g., What is your favorite number?).
There are two kinds of variables: numeric and string. A numeric variable represents any number. Numeric variables can be written as letters, letter-number pairs, or letter-letter pairs, (e.g., A, AB, A3). A string variable represents a group of numbers or letters or any combination of the two. String variables are written in the
25
same way as numeric variables, but with a $ at the end (e.g., A$, AB$, A3$). Both numeric and string variables must begin with an alphabetic character.
INPUT
An INPUT statement allows the computer to ask for information from the user. A string variable appears in the INPUT statement when a word is wanted; a numeric variable, when a number is wanted.
In the following example, A is a numeric variable in the INPUT statement because the question in line 10 asks the user to supply a number. Type:
NEW
10 PRINT "WHAT'S YOUR FAVORITE NUMBER?"
20 INPUT A
30 PRINT "YOUR FAVORITE NUMBER IS ";
40 PRINT A
50 END
RUN
When the computer encounters an INPUT statement, it prints a question mark, and then waits for the user to type in an answer. Type any number and then press HiiJhl?) .
ftiHT "WAT'S YOUR FAVORITE NUMBER? NPUT A...             ____________„ ..
PRINT A END
WHAT'S VOUR FAVORITE NUMBER?
YOUR FAVORITE NUMBER IS 7
String and numeric variables are not interchangeable. If you were to type SEVEN instead of 7, for example, an error message would appear on the screen.
*iNT "MHAT'S VOUR FAVORITE NUMBER?"
JRINT "VOUR FAVORITE NUMBER IS ".
END | NT'S VOUR FAVORITE NUMBER?
VOUR FAVORITE NUMBER IS 7
»*ADV. IN AT'S VOUR FAVORITE NUMBER?
Of course, you can rewrite the program to accept a word by using a string variable. Type:
NEW
10 PRINT "WHAT'S YOUR FAVORITE COLOR?"
20 INPUT A$
30 PRINT "YOUR FAVORITE COLOR IS ";
40 PRINT A$
50 END
RUN
26
PRiMI "MHAT'S VOUR FAUOR1TC COLOR?"
JSlHT "VOUR FAVORITE COLOR IS ";
PRINT AS
END
MHAT'S VOUR FAVORITE COLOR?
■» RED
VOUR FAUORITE COLOR IS RED
In both cases, line 20 (INPUT A or INPUT A$) assigns whatever number or word you have typed to variable A or A$ in memory, and then prints this value on the screen in line 40.
If you were to run the program again, this time giving a different answer to the question, "What's your favorite color?" the computer would assign a new value to the variable stored in memory.
A string variable can also be used to represent a combination of letters and numbers. Type:
NEW
1® PRINT "WHAT'S YOUR POSTAL ZIP CODE?"
20 INPUT P$
30 PRINT "YOUR POSTAL ZIP CODE IS ";
40 PRINT P$
50 END
RUN
"MHAT IS VOUR POSTAL CODE?"
"VOUR POSTAL CODE IS ";
AT IS VOUR POSTAL CODE? K2R 3P3
POSTAL CODE IS H2R 3P3
SUMMARY
There are two types of instructions: system commands and program commands. System commands, such as LIST, RUN and NEW, tell the computer to do something with or to a program. Program commands, such as PRINT and INPUT, are contained within the body of a program.
Numeric and string variables allow the computer to ask the user for some information. Numeric variables are used to represent numbers; string variables, to represent letters, groups of numbers, or a combination of letters and numbers.
27
i UNITV
PROGRAMMING IN BASIC (2)
ASSIGNING VALUES
Numeric and string variables can also be assigned specific values. In the following example, A is defined as 15, B as 7, and C as A*B or 15 x 7. Type:
NEW 10A=15 20B = 7 30LETC = A*B 40 PRINT C 50 END RUN
Now type:
NEW
10A$ = "10,20,30,40.....100"
20B$ = "THIS IS COUNTING BY 10'S"
30 PRINT A$
40 PRINT B$
50 END
$*"18.28.3B.48.....188"
$="THtS IS toUNTIMG BV 18'S" RIHT AS
RUN
REM
REM statements are remarks or comments that do not show up on the screen when the program is run, but do appear in a listing of the program. Type:
NEW
10 REM (YOUR NAME)
20 REM (TODAY'S DATE)
30 PRINT "THIS IS MY FIRST PROGRAM."
40 PRINT "I HOPE MY NAME WON'T APPEAR."
50 END
RUN
10*REM JOHN BROUN jooo
H »?N?C-T-?SH S M8?IRST PROGRAM,' 40 PRINT "I HOPE MV NAME WON'T APPEAR. 50 END
TBI's IS MV FIRST PROGRAM. HOPE MV NAME WON'T APPEAR.
28
REM statements can be placed anywhere in a program. They are often used to identify the programmer and the program. REM statements are especially useful when it comes to modifying or revising a program. (More about this in Unit VI.)
In the next example, REM statements are used to remind you of the value of the INPUT variables. Type:
NEW
10 PRINT "WHAT IS YOUR NAME?"
20 INPUT N$
30 PRINT "HELLO, ";
40 PRINT N$
50 PRINT " WHAT'S YOUR FAVORITE NUMBER?"
60 INPUT A
70 PRINT "WHAT'S YOUR FAVORITE COLOR?"
80 INPUT B$
90 REM N$ IS THE NAME 100 REM A IS THE NUMBER 110 REM B$ IS THE COLOR 120 PRINT "YOUR FAVORITE NUMBER IS "; 130 PRINT A
140 PRINT "YOUR FAVORITE COLOR IS "; 150 PRINT B$ 160 END RUN
T IS VOUR NAME?
AO. TOM
IT'S VOUR FAUORITE NUMBER?
I WAT'S VOUR FAUORITE COLOR? ? BLUE
VOUR FAUORITE NUMBER IS 7 VOUR FAUORITE COLOR IS BLUE
GOTO
GOTO is a program command that is used to send the computer to a line other than the very next in the program. Type:
NEW
10 PRINT "ADDITION"
20 PRINT "2 + 3 = "
30 INPUT C
40 IF C = 5 THEN GOTO 70
50 PRINT "WRONG. TRY AGAIN."
60 GOTO 20
70 PRINT "GOOD WORK!"
80 END
29
If the user answers the question incorrectly, the computer prints line 50: WRONG. TRY AGAIN. Line 60 tells the computer to go back to line 20: 2 + 3=.
GOTO does just what it says — it tells the computer to go to a specific line. In the program you have just typed, the GOTO state­ment creates a "loop" by telling the computer to go back to line 20. If you have not already done so, run the program. Type RUN.
A GOTO loop can run indefinitely. Type NEW and then press (3=nn3D ■ Then type:
10 PRINT "HELP! MY COMPUTER HAS GONE BERSERK!" 20 GOTO 10 30 END RUN
COMPUTER HAS GOME COMPUTER HAS 60NE COMPUTER HAS 60HE COMPUTER HAS 60HE COMPUTER HAS GOHE COMPUTER HAS 60HE COMPUTER HAS GOHE COMPUTER HAS GOHE COMPUTER HAS GOHE COMPUTER HAS GOHE COMPUTER HAS GOHE COMPUTER HAS GOHE COMPUTER HAS GOHE COMPUTER HAS 60HE COMPUTER HAS 60HE COMPUTER HAS GOHE COMPUTER HAS GOHE COMPUTER HAS 60HE COMPUTER HAS GOHE COMPUTER HAS GOHE COMPUTER HAS 60HE COMPUTER HAS GONE
_This is called an infinite loop. You can stop it by pressing This will cause a "break" message to appear on the
screen.
IF...THEN
IF. . THEN statements are among the most powerful relating to decision-making. They can be interpreted thus: if a particular situation is true, then the computer will act in a specific way; if a particular situation is not true, then the computer will not act in that specific way. Try this program:
Type NEW and press mainmi to clear the computer's memory. Then type:
10 PRINT "WHAT IS THE CAPITAL OF CANADA?"
20 INPUT C$
30 IF C$ = "OTTAWA" THEN 60
40 PRINT "NO. TRY AGAIN."
50 GOTO 10
60 PRINT "YOU'RE RIGHT!"
70 END
30
In line 30, the computer compares your answer (C$) with OTTAWA. If C$ = OTTAWA, then the computer jumps to line 60 and prints YOU'RE RIGHT! If C$ does not = OTTAWA, then the computer goes to line 40 and prints NO. TRY AGAIN. Line 50 tells the computer to go to line 10, which prints the question — WHAT IS THE CAPITAL OF CANADA?
Now, run the program. Type RUN.
Ł8 PRINT "MHAT IS THE CAPITAL OF CANADA'
28 INPUT C$
38 IF C$="0TTAUA" THEN 66
48 PRINT "NO. TRV AGAIN."
58 GOTO 18
€8 PRINT "YOU'RE RIGHT!"
END
READV.
RUN
WHAT IS I HE CAPITAL OF CANADA?
REVIEW
Let's review some of the new BASIC commands you learned in this unit. Type:
NEW
1© REM THIS IS A REVIEW
20 PRINT "WHOSE PROGRAM IS THIS?"
30 INPUT N$
40 PRINT "DOES IT WORK?"
50 PRINT "ANSWER YES OR NO, "; N$
60 INPUT A$
70 IF A$ = "YES" THEN 90
80 GOTO 110
90 PRINT "GOOD WORK, "; N$ 100 GOTO 120
110 PRINT "TRY AGAIN, "; N$ 120 END RUN
18 REM THIS IS A REVIEW
26 PRINT "WHOSE PR06RAN IS THIS?
38 INPUT N$
48 PRINT "DOES IT WORK?"
58 PRINT "ANSWER VES OR NO, "; N
68 INPUT AS
78 IF A$="VES" THEN 98
86 GOTO 116
98 PRINT "GOOD
,188 GOTO 128
118 PRINT "TRV A6AIN, "; N$
126 END
RUM
WHOSE PROGRAM IS THIS?
? JOHN
DOCS IT WORK?
ANSWER VES OR NO, JOHN
An INPUT statement is used when a programmer wants the user to enter data during the execution of a program. A question mark will appear on the screen to let the user know that it is his or her turn to type in some information.
The N$ that appears in lines 30, 50, 90, and 110 is called a string variable. It allows the user to enter letters in groups or "strings" that the computer will read, remember, and print as instructed.
The semicolon (;) that appears in front of the string variable in lines 50, 90, and 110 tells the computer to print the value of N$ on the same line.
31
The variable statement IF A$ = "YES" THEN 90 appears in line 70. This means, if the user answered "YES" to the question in line 40, then the computer will print GOOD WORK. A GOTO statement transfers control in the program without any conditions at all. An IF.. THEN statement transfers control only if certain conditions are true.
Here's another sample program. Remember to clear the computer's memory first by typing NEW and pressing l;lidll;M . Type:
05 REM THIS IS A REVIEW
10 PRINT "MULTIPLICATION CALCULATIONS"
20 PRINT "WHAT IS YOUR NAME?"
30 INPUT N$
40 PRINT "TYPE IN TWO NUMBERS, "
50 PRINT "SEPARATE THEM WITH A COMMA."
60 INPUT A,B
70 PRINT "WHAT IS"; A; "*"; B
80 INPUT C
90IFC = A*BTHEN 120
100 PRINT "NOT QUITE. THE ANSWER IS "; A*B 110 GOTO 130 120 PRINT "EXCELLENT!"
130 PRINT "DO YOU WANT TO TRY ANOTHER? Y/N" 140 INPUT Y$ 150 IF Y$ = "Y"THEN40 160 PRINT "THAT'S ALL, "; 170 END RUN
5 REM THIS IS A REUIEM _ |e PRINT "MHAT IS YOUR NAME?"
40   PRINT   "TYPE IN TUO NUMBERS."___.,
50   PRINT   "SEPARATE THEM U1TH A COMMA."
60   INPUT   A.B                           .. .
70   PRINT   "f«AT IS"; A; "«"; B
80   INPUT   C
fie'E^rSnIFM??. THE AHS*R IS".
I
110 GOTO 138
Jll jli« "&gC5bfcEKiV TO TRV ANOTHER*
IB If fi-'f ^EN 48
168 PRINT "THAT'S ALL. "; t?8 END
SUMMARY
REM allows you to enter statements that will not be seen when the program is run, but will appear on the screen when you list the program.
GOTO statements tell the computer to go to a line other than the very next in the program. IF. . THEN statements tell the computer to act in a specific way only if certain conditions are true.
32
I UNIT VI
HOW TO MODIFY A PROGRAM
In this unit, we'll look at two program commands that can be used to customize or modify programs to suit your own purposes: PRINT and READ.. .DATA. You've already learned about PRINT state­ments. READ.. .DATA is a command that tells the computer to read numeric or alphabetic data from DATA statements. A DATA state­ment contains information that will be used in a program (e.g., the correct answers to multiple-choice or addition questions). A DATA statement is always paired with a READ statement.
Each time the computer reads and stores a new piece of data from the DATA statement, it then goes back and reads the next piece of data, and then the next after that. When the computer has read enough information, it continues with the program.
Here's a program for you to type. Be sure to empty the computer's memory first; type NEW and press l;I^Jll;l?l.
10 REM THIS IS A MULTIPLICATION DRILL.
20 PRINT "THIS IS A MULTIPLICATION DRILL."
30 PRINT "IT WILL TEST THE 5X TABLE."
40 PRINT "TYPE IN THE ANSWER."
50 PRINT
60 FOR 1 = 1 to 10
70 REM F$ REPRESENTS THE QUESTION
80 READ F$(l)
90 NEXT I 100 FOR 1 = 1 to 10
110 REM E$ REPRESENTS THE ANSWERS 120 READ E$(l) 130 NEXT I 140 FOR 1 = 1 to 10 150 PRINT F$(I);:INPUTA$(I) 160IFA$(I) = E$(I)THEN 180 170 PRINT "NO, THE ANSWER IS " ; E$(l) 180 NEXT I
190 PRINT "THAT'S ALL." 300 DATA 5*1, 5*2,5*3,5*4,5*5,5*6 310 DATA 5*7, 5*8, 5*9, 5*10 320 DATA 5, 10, 15,20, 25, 30 330 DATA 35, 40, 45, 50 400 END RUN
33
LISTING THE PROGRAM
Let's go back and take a closer look at the program you have just typed. Type:
LIST 10-50
38 PRINT "IT HILL TESTTHE 5X TABLE. 46 PRINT "TVPE IN THE ANSWER." 56 PRINT
Notice the REM statement in line 10; it did not appear on the screen when you ran the program. It only shows up in a listing. Lines 20 to 50 are all PRINT statements: whatever appears within quotation marks will appear on the screen. Look closely at line 50. Nothing appears beside the word PRINT. If you were to run the program again, you would see that this gives a blank line. This is yet another use of the BASIC command PRINT: to leave space on the screen. Now type:
LIST 60-140
66 FOR 1=1 TO IB
76 REM FS REPRESENTS THE QUESTION
66 READ FS(I)
96 NEXT I
186 FOR 1=1 TO 18
118 REM FS REPRESENTS THE ANSWERS
128 READ E$(I)
136 NEXT I
146 FOR 1=1 TO 18
Notice the two REM statements. These tell you that F$ and E$ are the string variables that represent the questions and correct answers, respectively. In this program the XT' that appears in line 60 is the counter; that is, it keeps track of the number of questions that have appeared on the screen.
Clear the screen by pressing
and
Then
type:
LIST 15(M90
158 PRINT FS(I>, INPUT A$(I) 166 IF A$(I)=E$(I> THEN 188 176 PRINT "NO, THE ANSWER IS 186 NEXT I 196 PRINT "THAT'S ALL."
Line 150 tells the computer to print the first question in the DATA statement (F$), and wait for the user to input an answer (A$). Line 160 tells the computer that if A$= E$, it should then go to line 180, which tells the computer to present the next question (I), until all 10 questions have appeared on the screen. If A$ does not equal E$, then the computer goes to line 170, which tells it to print NO and to give the correct answer.
The program continues in this way until all 10 multiplication questions have appeared on the screen. Notice that the program uses the DATA statements (lines 300 to 330) in the order in which they appear. That is, the first question to appear on the screen is always 5*1, followed by 5*2, 5*3, etc. This limits the program's educational value since users can easily memorize the order of the questions and their answers. There are programming techniques to remedy this, but they do not come within the scope of this manual.
MODIFYING A PROGRAM
The multiplication program discussed above can be adapted to a variety of different purposes. Say, for example, you want to turn it into a geography drill that tests the names of countries and their capitals. What needs to be changed?
In line 10 you would have to change "multiplication" to "geography."
Line 20 would be: PRINT "THIS IS A TEST OF COUNTRIES"; Line 30: PRINT "AND THEIR CAPITALS."; and line 40: PRINT "NAME THE CAPITALS."
Similarly, the DATA statements would have to be changed to reflect the names of the countries and their capitals.
In order to make all these changes, you need only to type the line number, followed by the new information. Type:
10 REM THIS IS A GEOGRAPHY DRILL.
20 PRINT "THIS IS A TEST OF COUNTRIES"
30 PRINT "AND THEIR CAPITALS."
40 PRINT "NAME THE CAPITALS." 300 DATA NEW ZEALAND, POLAND, UNITED ARAB EMIRATES, THAILAND, EQUADOR, PORTUGAL 310 DATA PHILIPPINES, BOLIVIA, ZIMBABWE, ZAMBIA 32© DATA WELLINGTON, WARSAW, ABU DHABI, BANGKOK,
QUITO, LISBON 330 DATA MANILA, LA PAZ, SALISBURY, LUSAKA
Since there were 10 multiplication questions in the original program (i.e., 10 pairs of questions and answers), there can only be 10 geography questions (i.e., 10 pairs of countries and capitals); otherwise, the computer wouldn't be able to match the data evenly.
The computer automatically substitutes the new information for the old information.
35
To correct the references in the REM statements, type:
45 REM F$ REPRESENTS THE COUNTRIES 75 REM E$ REPRESENTS THE CAPITALS
To check that you have made these changes correctly, type:
LIST 45-75
Now, run the program. Type RUN.
SUMMARY
PRINT and READ. . .DATA statements can be used to modify programs. The command PRINT followed by no information will cause a blank line to appear in a program.
Computer programs can be modified to suit a number of different purposes. Remember, though, the number of pieces of data in the revised program must equal the number that appeared in the original program. Otherwise, the DATA statements will not match up evenly.
To make corrections in an existing program, simply retype the line. To delete a line from an existing program, type the line number, followed by no information.
36
i TROUBLESHOOTING
To clear the screen, (1) press E2H1 and 18B1 | , or (2) press and
To clear the screen ancf empty the computer's memory, (1) type NEW and press l-.l^MM , or (2) turn the computer off and on again.
To correct a typing error, use the cursor control keys
and the E
To correct an error in a program, simply retype the line.
To delete a line from a program, simply type the line number (with no information beside it) and press hmihlEl .
To insert a line in a program, simply type the line, beginning with a number to indicate its placement. The computer will automatically position the line in the correct place in the sequence.
To leave a blank line in a program, type PRINT with no information beside it.
To stop a program in the middle of its run, press
I EXPLANATION OF ERROR MESSAGES
NEXT WITHOUT FOR: If this message appears on the screen, you have probably left out a FOR statement in the program. List the program and check for the omission.
SYNTAX ERROR: When this message appears on the screen, it usually indicates a spelling and/or punctuation error. List the program and check for typing errors.
OUT OF DATA: This message appears on the screen when a READ statement is executed without sufficient data. Check the listing to see whether you have left anything out.
REDO FROM START: This means that you have attempted to execute an operation using an illegal parameter, such as typing in alphabetical data when numeric data was expected. Simply retype the entry so that it is correct, and the program will continue.
EXTRA IGNORED: This message appears when too many items of data were typed in response to an INPUT statement. Check your entry for commas (,) or colons (:) and delete them from the entry.
TYPE MISMATCH: This message appears on the screen when the user has attempted to assign a number to a string variable or vice versa.
37
I GLOSSARY
address:
Every letter, symbol, and piece of data is placed somewhere in the computer's memory. This memory location has an address, which is a number.
Beginner's All-purpose Symbolic Instruction Code. This is a computer language commonly used on microcomputers.
When a program is being executed, certain instructions will cause a transfer of control to another line.
When a program is running, you can stop it. The message that appears on the screen is BREAK IN (number). This means that you stopped the program at a particular line number.
A group of eight bits. A byte is generally considered to represent one character.
Either you or the computer is in control. This means that either it is your turn to enter data, or the computer's turn to execute a program.
This is a little, flashing box that appears on the screen to indicate the position of the next character to be typed.
Whenever there are errors in a program, you must find and correct them. This is known as debugging.
To prepare data for subsequent processing, e.g., by the deletion of errors.
All programs in BASIC must have an END statement.
To perform the operations specified by an instruction. The program will execute the commands within it once it has been given the RUN command.
A branch instruction in the BASIC language.
The actual physical components of a computer system.
A program statement that passes control to a different line, if a particular condition has been met.
When the computer immediately performs the commands we give it. When the computer is being used as a calculator or to create graphics without a program, it is in immediate execution mode.
BASIC:
branching:
break:
byte: control:
cursor:
debugging:
edit:
END:
execute:
GOTO: hardware:
IF...THEN:
immediate execution:
38
line:                        Every line must have a number identifying it in
a BASIC program. This group of digits is numbered sequentially, but not necessarily consecutively.
loop:                       A group of instructions that is executed more
than once.
machine code: This is the language actually used by computers to carry out instructions.
memory:                 A storage area for data within the computer.
microcomputer: A complete, small computer system.
numeric variable: A variable that represents a number.
peripheral:             Any device connected to a computer that is to
some degree controlled by the computer.
program:                A sequence of instructions that results in the
execution of an algorithm.
?:                            A short form for PRINT.
RAM:                      Random Access Memory is usable or working
memory. Anything stored here is lost when the machine is turned off.
REM:                      This stands for REMark. In a program, a REM
statement gives information, but it will not be printed on the screen.
RETURN:               A LiaiLLLJ key on a computer is used to
enter information. On some computers, the same function may be performed by an BOO key.
ROM:                      Read Only Memory keeps permanent
information within itself.
scroll:                     This refers to when the contents of the screen
move up or down by one or more lines.
software:                The instructions that tell hardware what to do
with data, i.e., programs.
statement:             A command or set of commands in one line of
a program.
string variable: A variable used to represent strings of characters, such as a word.
syntax error:          An error message that often appears in BASIC
programs.
system                   A command that will cause the computer to do
command:              something immediately, e.g., SAVE, LOAD, etc.
type mismatch An error message that occurs when the error:                       expected response is not given in a program.
39

Have a comment?

Comments