Programming Tips & Tricks for ATARI' Home Computers The exciting program ideabook, overflowing with pro techniques hints, secrets, shortcuts and 101 ready-to-run programs for ATARI Home Computers. by Alan North 101 Programming Tips & Tricks For ATARI® Home Computers 101 Programming Tips & Tricks For ATARI 9 Home Computers by Alan North ARCsoft Publishers WOODSBORO, MARYLAND SPECIAL EDITION FIRST PRINTING ©1983 by ARCsoft Publishers, P.O. Box 132, Woodsboro, MD 21798 USA Printed in the United States of America Reproduction, publication or use of the contents of this book, in any man¬ ner, without express permission of the publisher, is prohibited. No liability is assumed with respect to the use of the information herein. Trademark credits and software copyrights: ATARI is a registered trademark of Atari, Inc. Models 400 and 800 are trade¬ marks of Atari, Inc. Programming advice and applications software in this book are Copyright 1983 by ARCsoft Publishers ISBN 0-86668-922-2 Preface The ATARI Home Computer is one of the world’s most popular computer systems. Its lightweight, desktop design and powerful version of the BASIC programming language place it at the forefront of the new wave of personal com¬ puters for office, school and home use. Anything but a toy, its hardware configuration and system software make it a highly useful tool in the business environment and classroom as well as for prac¬ tical jobs around the home. In fact, the system software built into your ATARI Com¬ puter is so flexible and versatile that the need for this book became apparent. So many computing tasks can be accom¬ plished with an ATARI Computer system that an introduc¬ tion to the many techniques is needed. Applications software are the programs which make a computer do what you want. This book is written for those newcomers and beginners, as well as advanced novices and student programmers, who would like to tap the vast resources available in the ATARI Computer pack¬ age. This book will guide by example, instruct, and provide insights into the many ways BASIC can be put to use with ATARI Home Computers. —Alan North Tip Table of Contents Page Introduction 11 Fun & Games 1 Coin Toss 18 2 Traditional Dice Roll 18 3 See Two Dice 19 4 See Four Dice 20 5 Secret Message 21 6 Sound Off 22 7 Ring the Bell 1 22 8 Ring the Bell II 23 9 Mystery Clues 23 10 Original Hi/Lo Game 24 11 Code Groups 25 12 60-Second Timer 26 13 Find Highest/Lowest 27 14 Sorting Scores 28 15 Keeping Game Scores 29 16 Batting Average 30 17 Computer Rating Service 31 18 Box Score 32 Text on Text 19 Create a Quiz 36 20 Killing Time 37 21 Word-Error Trapping 38 22 Character Numbers 39 23 One-Time Password 39 24 Three-Tries Password 40 25 Multiple Passwords 41 26 Name In A Box 42 27 Entering: Zero Stop 43 28 Entering: Letter Stop 43 29 Title Billboard 44 30 Marching Numbers 45 31 Wipeout! 46 32 Sentence Writer 46 33 Categorizing 48 34 Alphabet Soup 49 35 Create A Table 50 36 Question & Answer 51 Gee Whiz 37 Gee Whiz I: Smart Adder 55 38 Gee Whiz II: Three-Digit Mystery 55 39 Gee Whiz III: Yes/No Decision Maker 56 40 Gee Whiz IV: First Alphabet Spotter 57 41 Gee Whiz V: Second Alphabet Spotter 57 42 Gee Whiz VI: Guess The Number 58 Number Crunching 43 Memory Tester 63 44 Number Reverser 64 45 Exam Score Sorter 64 46 Number-Error Trapping 66 47 Standard Deviation 67 48 Percentages 67 49 Logic Functions 68 50 Above & Below a Line 69 51 Factoring 70 52 Which is Smallest? 71 53 Which is Largest? 71 54 Reciprocals 72 55 Dump the Integer 73 56 Averages 73 57 Mid-Range Number 74 58 Rounding Off 74 59 Two-Digit Round Off 76 60 Percent to Decimal 76 61 Every 10th Answer 77 62 Random Sampler 78 63 Random Numbers: Zero To Nine 78 64 Random Numbers: Distribution 79 65 Random Numbers: Averages 81 66 Random Numbers: Sorting High/Low 82 Money Matters 67 Money Grows 86 68 Shopper’s Friend 86 69 Car Payments 88 70 To Nearest 95 Cents 89 71 To the Nearest Penny 89 72 Mark Up 90 73 Percentage Off 91 74 Dollars & Cents 92 75 Wages & Hours 92 76 Invoicing 93 77 Unit Price 94 78 Inventory Counter 95 79 Daily Code 97 Colorful Graphics 80 Aztec Art 101 81 Sine Wave 101 82 Hold That Pose 102 83 Okay, Now Wave 103 84 Moving Illusion 104 85 Super Moving Illusion 105 86 The Seamstress 107 87 Swimming Fish 107 88 Circling Dot 108 89 Box The Screen 108 90 Window Twinklers 109 91 Horn-ln-Funnel Art 110 92 Blackboard 110 93 Snowfall 111 94 Making Things Move 111 95 Draw A Box 112 96 Luminance Demonstrator 112 97 Draw A Line 113 98 Flashing Graphics Cursor 114 99 Boxed Title 115 100 Draw Bar Graphs 115 101 Background Cycler 117 Appendix A Atari BASIC Words 121 B Error Messages 124 C Companion Cassette Log 127 Introduction This book is designed as an idea starter and thought provoker for beginners and newcomers, as well as ad¬ vanced novices and student programmers, who have read the manual which came with the ATARI Home Computer and have read something very elementary on BASIC pro¬ gramming and now need some good ideas. This handbook gives you 101 different, complete pro¬ grams which will stand alone and run by themselves for learning purposes or which can be, if you wish, incor¬ porated into larger sets of instructions to your computer. These programs are written to be typed into your ATARI Computer just as you find them here with no pro¬ gramming needed. We assume you know how to turn on your computer and how to go about typing in a program but you don’t have to be a computer programmer to get started using these pieces of software. If you don’t relish the thought of typing the programs in this book, a companion cassette tape is included in selected ATARI Paks. The pre¬ recorded tape features all 101 tips and tricks ready to load into your ATARI Computer. Many tips in this book, in fact, will be of interest to old-timers in the program-writing game since we have presented many powerful new twists aimed at making the computer do more work more quickly. Amidst our 101 tips are countless secrets, shortcuts, tricks, hints, techniques and make-it-easier instructions. Each is intended to make you a more versatile program¬ mer and to make your programming effort lighter. Use this book to stimulate your thinking about how to approach various software problems. Use it to get good ideasfor new and different approaches to all your programming goals. As you grow and develop as a program writer, modify these programs and make your computer do even more! The printout As each program in this book was tested on an ATARI Home Computer, it was printed on paper directly from the computer’s program memory. In this manner, we have attempted to prevent those common typographical errors 11 which occur when computer programs are typeset by hand and proofread. The human hand and eye have not come between the computer and the printed page. You should find no errors at all in the programs in this book. Should you find something which appears to be in error, please send a postcard or letter to the author in care of ARCsoft Publishers, P.O. Box 132, Woodsboro, MD 21798 USA. He would like to know of problems so they can be corrected in future editions of this work. As you read through this book, you will find few uses of the BASIC word REM. REM stands for “remark” and is the BASIC instruction to the computer to “ignore this line.” REMs are used by some programmers to pad out programs and make them look longer, and to include sometimes-useful reminders about what certain segments of a program do. The trouble is REMs waste lots of precious memory space and add considerably to the typing time when entering a program into the com¬ puter. The author’s training in writing BASIC-language com¬ puter programs required a sharp editing pencil. REMarks and software explanations were out. Honing, fine-tuning and waste trimming were in. Use of coding-form program¬ writing worksheets, such as the ATARI Computer BASIC Coding Form published by ARCsoft Publishers, was in. The objective always was—and still is—to make the most efficient use of available memory. Even though they may be headed toward the same goal, no two programmers will write the exact same list of BASIC program lines from scratch. As you load these pieces of software into your ATARI Computer, you’ll make modifications to suit your personal needs and interests. For instance, exact wording of PRINT statements can be changed. Or two or more programs can be combined into one grand scheme. Your applications for these programs will vary. Standalone vs. subroutine All of the programs in this book can be used as por¬ tions of larger lists of instructions to your computer. That is, they can be written in as GOSUB or GOTO objects. To 12 do so, make appropriate changes to the first line (usually numbered 10 in this book) and the last line of each pro¬ gram. If you wish to create a subroutine, remember that every GOSUB must have a RETURN. RETURN must be the last line of a subroutine. If you work one of these programs into a larger set of instructions, be especially careful of your memory (variables) names. They must agree with and fit into those you are using in the main program. Also, be careful of line numbering. If you want to load more than one of these programs into your ATARI computer at the same time, be sure to use different sets of line numbers. Buzzer and clear screen The crooked, upward-pointing arrow ( ) used on the video display by the ATARI Computer is not found on line printers. So, we have used the right-pointing bracket to represent that symbol in this book. In all cases, you will find a REM in the same line indicating exactly what we have done. For example, you may see a line like this: 10 PRINT “J”:REM CLEAR SCREEN Such a line is an instruction to the computer to wipe everything from the video display screen. That is, clear the screen. To type in such an instruction, type in the line number, the word print and the first quotation mark. Then press the ESC key, press and hold the CTRL key, and press the CLEAR key. After that, type in the second quota¬ tion mark and the rest of the line. The crooked arrow display for screen-clear is ESC first, then CTRL and CLEAR simultaneously. If you wish to make the internal buzzer sound off, use ESC and CTRL and the number 2 key. This puts the arrow in inverse video (blue character on a white background). Here’s a line which you might see in this book: 10 PRINT “>”:REM BUZZER Here, you type in the line number, the word PRINT and the first quotation mark. Then press ESC, press and hold CTRL and press 2. After that, type in the second quotation mark and the rest of the line. 13 The crooked-arrow video display for buzzer is ESC first, then CTRL and 2 simultaneously. When you press these two combinations of keys, you’ll See a crooked arrow ( ^ ) on your TV screen (it’ll be in in¬ verse video when you use the sound buzzer combination), but when you print it out, the character will appear as a clos¬ ing bracket(}). Loading cassette programs If you’re using the 101 Programming Tips & Tricks companion cassette, follow these instructions to load the prerecorded programs into your ATARI Computer from your ATARI Program Recorder: NOTE: If you have an ATARI 400™ or 800™ Home Computer, make sure an ATARI BASIC cart¬ ridge is plugged into your computer (the cart¬ ridge should be plugged into the LEFT SLOT on the ATARI 800 Computer). 1 Insert the master program cassette in the program recorder. 2 Turn on your television and computer to get the READY prompt in the upper left-hand corner of the screen. 3 Make sure the tape is at its beginning (push the REWIND button on the program recorder until the tape stops), then set the tape counter on the pro¬ gram recorder to 000. 4 Type [CLOAD], then press [RETURN], You will hear a beep from the computer to remind you to press PLAY on the program recorder. 5 After pressing the PLAY button on the program recorder, press the [RETURN] key on your com¬ puter keyboard. The cassette tape will start turn¬ ing and the first program on the tape will load into the computer’s random-access memory (RAM). 6 When the tape stops, the first program has been loaded into the computer. The TV screen will dis¬ play a READY prompt. 7 To run the program, type RUN, then press return. To display the program line by line, type LIST, then press [RETURN], 8 When you’re finished with the first sample pro¬ gram and want to load another prograrh, type 14 NEW and press [RETURN], then repeat steps 4 through 7. You can advance or rewind the tape to any program on the cassette by first pressing the [ADVANCE] or [REWIND] button on the program recorder, then pressing the [STOPEJECT] button at the appropriate number indicated by the tape counter. To modify a program you’ve loaded into your com¬ puter, just retype the line that you wish to change, inserting the modifications, then press [RETURN], For example, pro¬ gram No. 8 on page 23 allows you to sound a series of bells. You can change the time delay between each sounding by modifying line 40. The original line reads: 40 FOR L = 1 TO 100:NEXT L To lengthen the time span between bells, retype line40: 40 FOR L = 1 TO 200:NEXT L Then type [RETURN]. When you run the program again, the time delay be¬ tween bells will be (in this case, since we doubled the num¬ ber) twice as long as the original. To shorten the delay, simply retype line 40, replacing 100 with a number less than 100, press [RETURN], then run the program again. To save programs you’ve modified, first remove the 101 Programming Tips & Tricks companion cassette from your recorder (press the STOP EJECT button and slip the cas¬ sette out) and insert another (data) cassette. Note the tape counter readout if you plan to use the companion cassette again after you’ve finished recording. If the data cassette you’re using already has programs recorded on it, press [ADVANCE] on the program recorder to wind the tape for¬ ward to the end of the last program recorded. Then wind the tape forward approximately 10 more counts (to make sure you don’t record over another program). Type CSAVE on your computer, then press [RETURN], The computer will sound two beeps to tell you to press both [PLAY] and [RECORD] on the program recorder, then press [RETURN] again. The cassette will then begin recording. When you’re finished recording, rewind the data cas¬ sette to the counter number you noted before switching tapes. Remove the data cassette and insert the companion cassette again. You’re ready to load another prerecorded program into your computer. 15 Many programmers use the words ENTER and RETURN interchangeably when writing about typing pro¬ grams into a computer. You may spot examples of this common use in this book. When we say ENTER a program or press RETURN, we mean tell the computer you have ended a line of a program or of data and are sending the info in. Book parts This book has seven important sections: Fun & Games, a set of new and different ideas you can put to use in writing games for your ATARI Computer; Text on Text, programming tips for handling words in your ATARI Computer; Gee Whiz, a group of quick-to-type programs you can use to excite your friends and family; Number Crunching, tips and tricks for handling numbers in your ATARI Computer; Money Matters, interesting programs to help you handle your household budget as well as store and office routines for businessmen; Colorful Graphics, designed to help you get more from your machine; And a handy Appendix of BASIC words and error messages as used in the ATARI Computers plus a work¬ sheet that allows you to record the exact starting position of each of the 101 programs on the prerecorded cassette. Naturally, these sections have been arbitrarily di¬ vided and may not be exactly as you would have sorted the programs herein. These divisions are not hard and fast lines, never to be crossed. Rather, programs shown here for use in games might be useful in a business program. Or part of a business program might be useful in a classroom or in a game. Try them all. You’ll learn something from each! 16 Fun & Games Coin Toss 1 Here’s a handy way to settle arguments. Toss a coin. Only this time, let the computer do the work! Type in the program. Run it. The computer will report heads or tails after each toss. For a new toss, press the RETURN key on your com¬ puter’s keyboard. Line 10 clears the screen. A random number—either zero or one—is generated at line 20 and tested to see if it is a zero. If it is, the computer prints heads. If not, the computer drops to line 30 where it prints tails. Lines 50, 60 and 70 accomplish the restart when you press RETURN. Program Listing 10 PRINT "} M :REM SCREEN CLEAR 20 IF "sPEN CLEAR SCREEN 20 DIM K*<1> 30 PRINT "TO ROLL DICE, PRESS RETURN” 40 INPUT K«SPRINT SPRINT 50 FOR L=1 TO 2 60 D0=INT(7* < RND(1)> ) 70 IF DOC 1 THEN 60 80 DP= I NT < 7* < RND < 1 ) > > 90 IF DRC1 THEN 80 100 PRINT "■a-********" 110 PRINT "* ";DQ; B * ";DR;" *" 12:0 PRINT "*■*•**■*****" 130 PRINT 140 NEXT L. 150 PRINT s CLR sGOTO 20 20 Secret Message Secret messages can be lots of fun! They often are composed of codes in which letters of the alphabet have been replaced by numbers. In this easy-to-use program, the computer generates a list of pseudorandom numbers and assigns one number to each letter of the alphabet. You use the numbers, in lieu of letters, to write notes to your friends. There is very little chance of the same number being assigned to two different letters because available numbers range from zero to 999. When typing this program into your computer,be sure to separate the alphabet letters with commas in line 100. By the way, note the nice two-column screen printing format! Line 250 does that. Program Listing 10 PRINT " } " : REIi CLEAR SCREEN 20 DIM L$(1),J$<1) 100 DATA A , B , C i D i E i F , G, H , 1 1 J , K , L , M, N , 0 , P,Q, R,S,T,U-V,W, .X, Y, 2 200 FOR N=1 TO 13 210 C=INT(1000*":REM BUZZER 40 FOR L=1 TO 100 s NEXT L. 50 NEXT N Mystery Clues Want to create your own murder mystery? Figure out whodunit and write your program backwards from there. When your players make wrong guesses, give them tan¬ talizing clues. Here’s a short program which you can load into your computer in a matter of minutes. Key it in and try it out. It shows how you can add clues to your mysteries. For simplicity, we assume here the Butler did it. Note that, in line 20, we are making him equal to X$. At line 30, the computer stops to ask you whom you think did it. Your answer is recorded in A$. In line 40, your answer, lodged in A$, is compared with the computer’s already-certain knowledge that the Butler did it. A$ is compared with X$. If they agree, and 23 only if they agree, the computer displays the message, "You guessed it.” If you got it right, things will end right there. If, however, you missed it, program execution (sorry about using that word in a murder mystery!) drops to line 50 where we hear the computer, “Clue: servant.” After deftly dropping that clue, the computer moves back and runs through the whole affair another time. It will keep running through it until you answer, “Butler,” in response to its question in line 30. Program Listing 10 PRINT "}":REM CLEAR SCREEN 15 DIM A$ ( 6 ) n X'$ < 6 ) 20 X$="BUTLER" 30 PRINT "WHODUNIT INPUT A* 40 IF X*=A* THEN PRINT :PRINT "YES, YOU GUESSED IT":PR INT :GOTO 20 50 PRI NT :PRINT "CLUE: ",”SERVANT":PRINT :PR INT :GOTO 20 10 Original Hi/Lo Game Here it is. Where everybody started in micro¬ computer programming back in the Seventies. The first game ever played was a high-low guess-the-number routine. The computer selects a secret number. You try to guess it. The computer tells you whether or not you are too high, too low, or right on the number. Here’s how it works: the secret number can be zero to 1000. Line 100 generates a random number (the secret number) and stores it. Line 210 asks you to guess the number. Lines 300-310 decide if you are right or wrong. Line 220 keeps track of the number of attempts. 24 Program Listing 10 PRINT "}":REM CLEAR SCREEN 20 T=0 10© R=IMT(1000*(RND<1)>> 20© PRINT ":REM BUZZER 21© PRINT "GUESS THE NUMBER":INPUT B 220 T=T+1 230 PRINT :PRINT "THAT WAS TRY NO. "ST 300 IF B>R THEN PRINT :PR INT "TOO HIGH GUESS AGAIN":INPUT B:GOTO 220 310 IF B":REM CLEAR SCREEN 20 FOR L=1 TO 5 30 N= I NT (91 * ( RND ( 1 ) ) ) 40 IF N<65 THEN 30 50 PRINT chr$-:n>; 60 NEXT L 70 PRINT :GOTO 20 25 Sample Run CYGQH MWHOJ KAFDH XMIAJ CTWRQ BTPNC BZPDO VFEZK QDFGN REMSF HALVN ANBWO NTVEA NXECR RUNSX I DP LG PODAA TPKII 60-Second Timer A one-minute timer can be very handy for fun-n- games. This easy-to-use clock “ticks” as it counts off seconds up to 60. When it reaches 60 seconds, it rings an alarm. The number of seconds counted can be changed by changing the number 60 in line 20. The clock can be calibrated by changing the number 200 in line 50. Line 50 is a time-delay loop set for approxi¬ mately one second. Lines 70-90 provide a rapid burst of five beeps when the clock reaches 60 seconds. To change the length of this alarm, change the number 5 in line 70. Program Listing 10 PRINT "}”!REM CLEAR SCREEN 20 FOR T= 1 TO 60 30 PRINT "}":REH BUZZER 40 PRINT T,"SECONDS" 50 FOR L=1 TO 200:NEXT L 60 NEXT T 70 FOR E=1 TO 5 80 PRINT ">":REM BUZZER 90 NEXT E 26 Find Highest/Lowest Suppose we have a list of people and each person has been assigned a number or score. This program accepts the names and scores and sorts out the persons with the highest and lowest scores. Here’s how it works. At line 20, the memory is DIMensioned to hold data. Lines 30-110 take in the info on each person. As each person’s score is entered, lines 70- 100 determine if it is higher or lower than all previous scores. If higher or lower, it is so noted. To complete data entry, simply pressRETURNwithout data. That will prompt the computer, at lines 130 and 140, to print the lowest score and the highest score. Program Listing 10 PRINT ">"sREM SCREEN CLEAR 20 DIM N$ ( 20) ,LN$<20) ,HN$<20> , K$ < 1 ) 30 PRINT "}":REM BUZZER 40 PRINT "NAME:INPUT N$ 50 IF N$="" THEN 120 60 PRINT "SCORE:INPUT S 70 X=X+1 80 IF X=1 THEN LS=S:LN$=N$:HS=S:HN$=N$ 90 IF SHS THEN H3=S:HN$=N* 110 GOTO 40 120 PRINT :PR INT 130 PRINT LN$;" SCORED LOWEST AT ";LS 140 PRINT HN$5" SCORED HIGHEST AT ";HS 150 PRINT :PRINT :PRINT :PRINT 160 PRINT "TO DO MORE, PRESS RETURN" 170 INPUT K$ 180 CL.R : GOTO 10 27 Sorting Scores Here’s how to sort a set of scores. Any numbers can be used. Zero is assumed to be lower than any positive number and a negative number is lower than zero. Key in as many numbers as you like. Then key a zero when you wantyourcomputertocomputefinalresults.Ob¬ viously, a zero cannot be in the set of numbers you are sorting since we use zero to get out of the input loop. At the end of the RUN, the computer will tell you which number is lowest and which is highest. Program Listing 10 PRINT "i"s REM CLEAR SCREEN 20 DIM K$( 1 ) 30 PRINT "TYPE IN A SCOREs "ssINPUT N 40 IF N=0 THEN 100 50 S=5+l 60 IF S=1 THEN LN=NsHN=N 70 IF NHN THEN HN=N 90 GOTO 30 100 PRINT 110 PRINT "LOW NUMBER IS ";LN 120 PRINT "HIGH NUMBER IS ";HN 130 PRINT SPRINT SPRINT 140 PRINT "FOR A DIFFERENT" 150 PRINT "SET OF NUMBERS," 160 PRINT "PRESS RETURN" 170 INPUT K$ 180 CLR sGOTO 10 Sample Run RUN RETURN TYPE IN A SCORE 22 RETURN 55 RETURN 28 77 11 0 RETURN RETURN RETURN LOW NUMBER IS 11 HIGH NUMBER IS 77 Keeping Game Scores Writing a computer football game? Spelling bee? Cave adventure? No matter what kind of fun you are preparing, you’ll need a way to keep score. Here’s how. The wealthy English duke has just been killed in our little mystery game. In lines 10 through 160 of our program listing below, you play the game, attempting to find out whodunit. The trick here is in the scorekeeping. Noteline170.lf you guessed correctly in response to the queryinline160, at Iine170 thecomputer will give you credit by adding one point to your score stored in memory location R. It does that by comparing your Iine160answer stored in P$ with the correct answer stored in A$. If you blew it and guessed wrong, the program drops below Iine170to line 180 where it increases your “wrong score” by adding one point to W. If you got a W+1 at line 180, the program moves back tolinelOOand gets you to try again. If you scored a victory and got an R+1 at Iine170,the program jumps to line 200 where it stops to display your total right and wrong score. After that, it’s back to line 40 for a complete new run- through. Program Listing 10 PRINT S REM CLEAR SCREEN 20 DIM A$<7>,B*<7>,C*(7>»D*<7> 30 DIM E$<7>,F*(7),G*<7>,P*<7> 40 S=INT<7*>> 50 IF SCI THEN 40 60 FOR L~i TO S 29 70 READ A$ 80 NEXT L 90 RESTORE JPRINT "JKMOKMOKMOiOK^KJKMOKMOKJIOKiKMtMOK 11 100 PRINT "WHO KILLED THE DUKE ?" 110 READ B*,C$,D*,E*,F$,G* 120 RESTORE 130 PRINT JPRINT "WAS IT THE..." 140 PRINT B$,C*,D*,E*,F*,G* 150 PRINT JPRINT ")"JREM BUZZER 160 PRINT "WHODUNIT "JJINPUT P$ 170 IF A$-P$ THEN R==R+1 JPRINT JPRINT "OK YOU ARE RIGHT" JPRINT "IT WAS THE "JA*JGOTO 200 180 PRINT JPRINT "NO! NOT THE "JP* J W-W+lJ PRINT J GOTO 100 200 PRINT 210 220 230 30 0 PRINT "YOUR SCORE IS♦* ♦ " PRINT RJ" RIGHT ",WJ" WRONG" PRINT JPRINT J GOTO 40 DATA BUTLER,NANNY,GARDENER,BURGLAR ,SON,WIFE Batting Average Once you know the number of times you were right and wrong in a game, as in Tip Number 15, it’s fun to convert those raw numbers to a batting average. Numbers right and numbers wrong take on a new meaning when changed to a batting average. Folks seem to be able to understand a batting average better. Our program, starting at line 900, is a partial listing designed to be tacked onto the end of your longer game program to display the final results of play. It will show the number of tries, number of right answers, percentage right, and batting average. You’ll want to test load this program so add lines 10 and 800 as shown. Line 800 will give you the R and T values you’ll need going into the program at line 900. 30 Program Listing 10 F : 'RINT i REM CLEAR SCREEN 80 0 PRINT "NUMBER RIGHT J "J 810 INPUT R 820 PRINT "NUMBER TRIES: "J 830 INPUT T 900 PRINT R;" RIGHT" 910 PRINT "IN "JTJ" TRIES" 920 D-R/T t P=10 0*D: B--INT (1 0 *p+0*5) 930 PRINT "THAT'S "JPJ" PERCENT" 940 PRINT "YOU ARE BATTING "JR Computer Rating Service Of course, once you know a player’s batting average it still might need some interpretation. In this program, the computer takes a look at a batting average and makes a comment. Remember that this listing, starting here with line 800, is a partial program to be tacked on the end of a longer game. Note that, at 800, you already have values for G (number right) and E (number of tries). Line 810 converts those raw numbers to a batting average (H). Program Listing 10 PRINT "}":REM CLEAR SCREEN 700 PRINT "NUMBER RIGHT: "; 710 INPUT G 720 PRINT "NUMBER OF TRIES: "; 730 INPUT E 800 PRINT G5" RIGHT IN ";E;" TRIES" 810 H=INT((G/E)*1000) 820 PRINT "YOU ARE BATTING ";H 830 PRINT "YOU ARE "; 840 IF H<100 THEN GOTO 910 850 IF H<300 THEN GOTO 920 860 IF H<500 THEN GOTO 930 31 870 IF H< 7 00 THEN GOTO 940 880 IF HC900 THEN GOTO 950 900 PRINT "HALL OF FAME":GOTO 960 910 PRINT ”THE PITS":GOTO 960 920 PRINT "POOR";GOTO 960 930 PRINT "AVERAGE":GOTO 960 940 PRINT "TOP NOTCH":GOTO 960 950 PRINT "DAMN NEAR PERFECT!" 960 PRINT "YOUR BATTING AVERAGE IS " ?H 970 END Box Score To dress up scores during and at the end of a game program, use this method of putting those scores in a box. The box around the score will highlight it and jazz up your video display. Program Listing 10 PRINT ">";REM CLEAR SCREEN 20 DIM N$<20>,SS<8> 30 PRINT "PLAYER’S NAME: 40 INPUT NS 50 PRINT "PLAYER’S SCORE: 60 INPUT S 70 PRINT 80 S$=STRS(S> 90 LN=LEN< NS)+LEN,Df(20) 20 DATA FIRST ..GEORGE WASHINGTON 30 DATA SECOND., JOHN ADAMS 40 DATA THIRD,THOMAS JEFFERSON 50 DATA FOURTH,JAMES MADISON 60 DATA FIFTH,JAMES MONROE 70 DATA SIXTH,JOHN QUINCY ADAMS 80 PRINT "HOW MANY U.S. PRESIDENTS" 85 PRINT "CAN YOU NAME" 98 R= I NT < 1 2* < RND < 1 ) ) ) 100 IF R<1 THEN 90 110 IF INT = R/2 THEN R=R+1 36 120 FOR L=1 TO R 130 READ S$ 140 NEXT L 150 PRINT SPRINT 160 PRINT "WHO WAS THF" 170 PRINT 5* 1S0 PRINT "PRESIDENT OF THE U.S.” 190 READ C$ 200 INPUT D$ 210 PRINT 220 IF D$=CS THEN PRINT "THAT’S CORRECT " • GOTO 240 230 PRINT "THAT’S WRONG" 240 PRINT "THE ";S$;" PRESIDENT WAS " 250 PRINT C* 260 RESTORE 270 PRINT SPRINT 230 GOTO 90 20 Killing Time Sometimes, it may seem to you as if the computer will never get to the result of a job. You understand the processing delay but your non-computer friends may not. They could be confused by the wait and think the com¬ puter is “broken.” To keep their minds off the slowness, give them something to look at while the computer is “thinking.” The added, extra lines, numbered 50, 60, 70 and 80, take up more processing time but make for less confu¬ sion. Computing may take a bit longer but your fun will be increased. If you delete lines 50-80 you’ll see how the program runs faster but the blank screen is confusing. Program Listing 10 PRINT ">":REM SCREEN CLEAR 20 PRINT "GIVE ME A NUMBER INPUT N 37 30 FOR L=1 TO N 40 X=X+L 50 FOR T=1 TO 100sNEXT T 60 PRINT "}»SREM SCREEN CLEAR 70 FOR T= 1 TO 100:NEXT T 80 PRINT "I AM THINKING” 90 NEXT L 100 PRINT ">":REM SCREEN CLEAR 110 PRINT "I HAVE THE ANSWER":PRINT 120 PRINT "THE TOTAL OF ALL NUMBERS" 130 PRINT "FROM 1 TO ";N?" IS "?X 200 PRINT :PR INT :PRINT 210 CLR :GOT0 20 Word-Error Trapping The same kind of error trapping is available for strings. Suppose the program, as in this example, asks at line 10 for a word. It is looking for YES or NO. If it gets a YES, then line 20 sees that it got what it wanted and moves operations along to line 100. If it gets a NO, then line 20 hasn’t received what it wants so program execution moves on to line 30. Here, at line 30, the program finds something useful and shoots operations down to line 200. If, however, neither YES nor NO were entered at line 10, then neither lines 20 nor 30 would be satisfied so ac¬ tion would drop to line 40. Here, the error is trapped by commanding the operator to give one of the two correct answers. Then, at line 50, the operation is returned to line 10 for a new try at the correct input. Program Listing 5 DIM A$<3):PRINT ">":REM CLEAR SCREEN 10 PRINT "WANT TO PLAY AGAIN "5:INPUT A$ 20 IF A$="YES" THEN 100 30 IF A$="NO" THEN 200 40 PRINT "PLEASE ANSWER ONLY YES OR NO" 38 50 PRINT 100 PRINT 110 PRINT 200 PRINT 210 PR INI¬ GO TO 10 "THANK YOU FOR THAT 5 PRINT :GOTO 10 "THANK YOU FOR THAT SPRINT :GOT0 10 " 5 A$ " ; A$ Character Numbers This brief program displays the ASCII value for each keyboard character, side-by-side with the character it stands for. You will be able quickly to tell what each number prints. Line 40 is a timing loop to slow down the presenta¬ tion so you can digest the information. To make it even slower, increase the number 400 in line 40. To make it faster, decrease the number 400 in line 40. The computer’s chime will ring after it reaches 255. Line 60 provides the beep. Program Listing 10 2 0 21 22 23 30 40 50 60 PRINT ">"JREM SCREEN CLEAR FOR N=0 TO 252 IF N>26 AND N<32 THEN 50 IF N>124 AND NCL28 THEN 50 IF N>154 AND N<160 THEN 50 PRINT N t CHR$(N) FOR T=1 TO 400JNEXT T NEXT N PRINT ">"{REH BUZZER One-Time Password If you don’t want unauthorized use of your programs insert a requirement that a user know a password. This particular routine allows only one try at entering a correct password. For our password, we have selected “elephant” and stored it in line 30. You can change the password to whatever you like. 39 If a correct attempt at entering the password is made, program action will progress to line 100. Other¬ wise, action drops to line 40 and action ends. Program Listing 10 PRINT ")”:REM CLEAR SCREEN 15 DIM A$(8> 20 PRINT 11 WHAT IS THE PASSWORD " t s INPUT AS 30 IF A*="ELEPHANT" THEN 1.00 40 END 100 PRINT "YOU GOT IT RIGHT" 110 PRINT "NOW THE PROGRAM WOULD RUN” Three-Tries Password Here the software lets you try three times to enter the correct password. You don’t get to go forward with the program if you don’t get it right in three tries. Again the password is “elephant” and is stored in line 30. You can change the password to whatever suits you. Lines 40 to 60 allow the three attempts. If no good after three tries, then END. Program Listing 10 PRINT "}"sREM CLEAR SCREEN 15 DIM AS(8) 20 PRINT "WHAT IS THE PASSWORD INPUT AS 30 IF AS="ELEPHANT" THEN 100 40 B=B+1 50 IF B=3 THEN END 60 GOTO 20 100 PRINT "YOU GOT IT RIGHT" 110 PRINT "NOW THE PROGRAM WOULD RUN" 40 Multiple Passwords Here’s a really complex password entry system. It has a unique “account number” and a password for each person. This will allow several different persons access to the program but each person will have a different com¬ bination to the lock! account number password 12345 zebra 23456 goose 34567 trout 45678 snake Each individual user must correctly enter his unique account number and then his own personal password. If account number is wrong, then the password never can be right. If account number is okay but password doesn’t match, the user gets no run. You can add users to this program by adding lines to the 300-340 subroutine. Program Listing 10 PRINT "}":REM CLEAR SCREEN 15 DIM PS$<5),PW$(5) 20 FOR L=1 TO 3 30 PRINT "YOUR ACCOUNT NUMBER: ",sINPUT UA 40 GOSUB 300 50 PRINT "PASSWORD:",,:INPUT PS$ 55 IF PS*=="" THEN 50 60 IF PS*=PW$ THEN 100 70 NEXT L 80 END 100 PRINT "YOU GOT IT ALL RIGHT" 110 PRINT "NOW THE PROGRAM WOULD RUN" 120 END 300 IF UA=12345 THEN PW$="ZEBRA" 310 IF UA=23456 THEN PW$="GOOSE" 41 320 IF UA=34567 THEN PW$="TROUT 330 IF UA=45678 THEN PW$="SNAKE 340 RETURN Name In A Box Put your name up in lights! Or, at least, on the video display screen of your ATARI Computer. This short program creates a box on the screen and puts a name you have specified into that box. The name is highlighted. You can change what the box is composed of by changing the asterisks in lines80,110 and 130. Program Listing 10 PRINT M >"sREM SCREEN CLEAR 20 DIM NS(26),K*<1) 30 PRINT sPRINT "WHAT IS YOUR NAME" 40 INPUT m 50 LN=LEN(N$) :LT==LN+4 60 PRINT :PRINT "}":REM CLEAR SCREEN 70 FOR L.= 1 TO LT 80 PRINT "*•; 90 NEXT L 100 PRINT 110 PRINT "* ";NS;" *" 120 FOR L=1 TO LT 130 PRINT 140 NEXT L 150 FOR L=1 TO 10 160 PRINT 170 NEXT L 180 CLR s GOT0 20 42 Entering: Zero Stop Here’s another way to conclude an entry loop: have the computer be on the lookout for a plain zero. When a zero is entered, the computer will jump out of the entry cy¬ cle and on to further action. This program totals numbers as they are added and accumulates them in memory location B. If one of the numbers entered is a zero alone, then line 110 will spot it and send the computer on down to line 200, breaking the entry cycle. Naturally, you can’t use a zero in a string of numbers to be added since zero causes the computer to quit enter¬ ing and get on with displaying. Program Listing 10 PRINT ">":REM SCREEN CLEAR 20 B=0 100 PRINT "GIVE ME A NUMBER":INPUT A 110 IF A~0 THEN 200 120 B=B+A 130 PRINT !GOTO 100 200 PRINT SPRINT SPRINT 210 PRINT "THE TOTAL. OF THOSE NUMBERS IS ” ;: B 300 PRINT SPRINT SPRINT SPRINT 310 GOTO 2 0 Entering: Letter Stop One way to conclude an input series, and get out of its entry loop, is to use a key letter to promote a jump. In this brief example, we input numbers, at line 100, as string values. If we give the computer an X rather than a number, it will jump down to line 200 for new action. Numbers keyed in are stored first as strings. Then line 120 changes them to number values for the addition in line 130. 43 Program Listing 10 PRINT ”}"sREM CLEAR SCREEN 20 CL.R 30 DIM A$ ( 20) 100 PRINT "GIVE ME A NUMBERsINPUT A* 110 IF A$ :r -" X" THEN 200 120 E=VAL9 THEN 20 50 PRINT X? 60 GOTO 30 45 31 Wipeout! Warning: handle with care! Careless operation of this program can cause you a lot of extra work. Key in the program. Run it. When it asks for the password, be sure to give it what it wants or it will erase itself. That’s right, the entire contents of program memory down the tubes! Here’s how it works: The password, in this case Tracey , is asked by line 20. You give it a password. In line 30, your answer is com¬ pared to the true password. If correct, action goes to line 50. If incorrect, the program goes to line 40. The NEW statement in line 40 erases everything from program memory. You can change the password in line 30 to any letters, numbers or keyboard symbols of your choice so long as it is 20 characters or less (the size of the DIMension statement). Watch out when testing. A wrong password can cause a lot of retyping. Program Listing 10 PRINT "}"s REM CLEAR SCREEN 15 DIM PS(20) 20 PRINT "WHAT IS THE PASSWORD; "; ;INPUT P$ 30 IF P$="TRACEY" THEN 50 40 NEW 50 PRINT "CORRECT" 60 PRINT P$;" IS THE PASSWORD" Sentence Writer Practice your English! Exhibit your knowledge of nouns and verbs. This program leads the computer to solicit individual words from you and use those words to create sentences. 46 Besides helping you better understand verbs, nouns and simple declarative sentence structures, the program demonstrates the computer’s ability to simulate conversation and communication. Lines 20, 30 and 40 take in the words. You may modify the program to suit your own interests or needs. Program Listing 10 PRINT " }" ;REM CLEAR SCREEN 15 DI li N$ ( 15) , V'*( 15) , S*< 15) , K$ ( 1 ) 20 PRINT "A PLURAL. NOUN: " , s INPUT N$ 30 PRINT "A VERB:INPUT V$ 40 PRINT "A SINGULAR NOUN:",:INPUT S$ 50 PRINT SPRINT 60 PRINT "THE ";N$;" ";y$;" ";s$;"," 70 FOR L=1 TO 10:PRINT :NEXT L 80 PRINT "PRESS RETURN" 90 INPUT K* 100 CLR :GOT0 10 Sample Run A PLURAL NOUN = ? DOGS A VERB = ? LOVE A SINGULAR NOUN = ? FOOD THE DOGS LOVE FOOD. A PLURAL NOUN = ? BOXES A VERB = ? HOLD A SINGULAR NOUN = ? WATER THE BOXES HOLD WATER 47 Categorizing A large quantity of numbers can be categorized and thereby cut down into a smaller quantity of numbers. See our example: it takes test scores and divides them into ranges labeled A, B, C, D, and F. The program assumes exam or test scores in a range of zero to 100. The letter grades include zero to 59, F; 60-69, D; 71-79, C; 80-89, B; 90-100, A. Key in as many scores as you like and then enter the letter X to stop the entry cycle. Lines 100-140 sort all scores into the A through F categories. Lines 150-170 sort highest and lowest scores. Line 200 finds mid-range and average scores. Program Listing 10 PRINT "I":REM CLEAR SCREEN 20 DIM S$(10),K$(1) 30 PRINT "ENTER A GROUP OF SCORES" 40 PRINT "FROM 0 TO 100, ONE AT A TIME" 50 PRINT "ENTER X AFTER LAST SCORE" 60 PRINT :PRINT "SCORE: "isINPUT G$ 70 IF G*="X" THEN 200 80 G=UAL 90 N=N+1 100 IF S<60 THEN F=F+1:GOTO 150 110 IF G<70 THEN D=D+l:GOTO 150 120 IF G<80 THEN C=C+l:GOTO 150 130 IF G<90 THEN B=B+l:GOTO 150 140 A=A+1 150 IF N=1 THEN L=G:H=G 160 IF GH THEN H=G 1S0 S=S+G 190 GOTO 60 200 P--S/N : M=L+ < ( H-L.) /2 ) 210 PRINT "}":REM SCREEN CLEAR 220 PRINT "THERE WERE ";N;" SCORES" 230 PRINT "RANGING FROM "?L?" TO ";H 48 240 PRINT SPRINT "MID-RANGE SCORE:",M 250 PRINT "AVERAGE SCORE:",P 260 PRINT SPRINT "TOTALS FOR EACH LETTER GRADE s » 270 PRINT SPRINT "As",A 280 PRINT "B s " ,E 290 PRINT "C s",C 300 PRINT "Ds",D 310 PRINT "F:",F 400 PRINT SPRINT SPRINT 410 PRINT "FOR MORE, PRESS RETURN" 420 INPUT K$ 430 CL.R s GOTO 10 Alphabet Soup Sure, everybody knows there are 26 letters in the alphabet. But, do you know which letter is number 20? Number 5? Number 17? Well, your computer knows! Type in this short ready-to-run program. RUN it. The computer will spit out number-and-letter combinations all day long. The number on the left is the position in the alphabet of the letter on the right. It’s a fun way to demonstrate to your friends just how “smart” the computer is! Program Listing 10 PRINT " !• " s REM CLEAR SCREEN 20 DIM X$(l) 30 P=INT(91 * < RND(1 ) ) ) 40 IF P<65 THEN 30 50 X$=CHR$ "sREM SCREEN CLEAR 10 PRINT "A”,"B","C"SPRINT 20 GOSUB 900 30 IF X>50 THEN A=A+l:GOTO 20 40 GOSUB 900 50 IF X>50 THEN B=B+l:GOTO 20 60 GOSUB 900 70 IF X >50 THEN C=C+l:GOTO 20 100 PRINT A,B,C:IF T=19 THEN 200 110 A=0:B=0:C=0:T=T+1:GOTO 20 200 GOTO 200 900 X= INT(100*(RND(1)}> 910 RETURN 50 Question & Answer Here’s how to use the DATA statement, and the com¬ puter’s ability to, search for data, to create a Q&A. We put DATA in lines 20-130. It could be anywhere in the program. For instance, at the end at lines 400-510. The computer sees two items in each data line. Pro¬ gram lines 140 and 160 force the machine to take only odd-numbered data from the list. That is, S$ in line 180 is always the first piece of data in a data line. And C$ in line 210 is always the second item in a data line. Line 230 checks to see if you answered the line 220 question cor¬ rectly. Program Listing 10 PRINT " } " s REM CLEAR SCREEN 15 Dili S$(9) , C$<2> ,D$<2) 20 DATA JANUARY,31 30 DATA FEBRUARY,28 40 DATA MARCH,31 50 DATA APRIL,30 60 DATA MAY,31 70 DATA JUNE,30 80 DATA JULY,31 90 DATA AUGUST,31 100 DATA SEPTEMBER,30 110 DATA OCTOBER,31 120 DATA NOVEMBER,30 130 DATA DECEMBER,31 140 R=INT(25*(RND(1))) 150 IF R<1 THEN 140 160 IF INT< R/2)=R/2 THEN R=R-1 170 FOR L=1 TO R 180 READ S$ 190 NEXT L 200 PRINT "MONTH IS ";S$ 210 READ C$ 220 PRINT "HOW MANY DAYS INPUT D$ 230 IF D$=C$ THEN PRINT SPRINT "CORRECT" :GOTO 300 51 240 PRINT s PRINT "WRONG" 300 PRINT "NUMBER OF DAYS IS ";C* 310 RESTORE 320 FOR L~1 TO 5 5 PRINT :NEXT L 330 CL.R ! GOT0 15 52 Gee Whiz 37 Gee Whiz I: Smart Adder These six programs, in this section of the book, make up our Gee Whiz series. One of the fun ways to use your computer is in wowing your friends.Next time they ask, “But, what can it do?”, show them its uncanny abilities at adding, spelling, writing upside down, even cracking jokes. Try these six Gee Whiz programs on your friends. You’ll love their reactions. Smart Adder is the first in the series. When your neighbor drops in for a cup of coffee, bring out the compu¬ ter for a demonstration of its lightning speed. This program adds long strings of numbers in a flash. You give the computer a number. It starts at 1 and adds all numbers up to and including your number. For instance, if you give it a five, it will add 1 plus 2 plus 3 plus 4 plus 5 and display the result. Ask your neighbor how fast he or she can add all the numbers to 100. It should take several minutes. While he’s working on it, let your computer do it in a split sec¬ ond.Your neighbor’s reaction is bound to be,“Gee whiz!” Program Listing 10 PRINT "}":REM CLEAR SCREEN 20 PRINT "GIVE ME A NUMBER: "5:INPUT N 30 IF N<1 THEN 20 40 FOR L= 1 TO N: X = X+l_ :NEXT L. 50 PRINT "}":REM BUZZER 60 PRINT "THE TOTAL OF 1 TO ";N;" IS ";X 70 PRINT SPRINT sCLR :GOTO 20 38 Gee Whiz II: Three-Digit Mystery Have your neighbor secretly select any three-digit number in which all three digits are the same. Then have 55 him tell the computer only the sum of those three digits. The computer will identify his secret number! Program Listing 10 PRINT JREM screen clear 20 PRINT "SELECT A THREE-DIGIT NUMBER" 30 PRINT "ALL THREE DIGITS THE SAME" 'iU PRINT 50 PRINT "ADD THE THREE DIGITS TOGETHER" 60 PRINT 70 PRINT "WHAT IS THE SUM" 80 PRINT "OF THE THREE DIGITS "J 90 INPUT N 100 IF N<3 OR N>27 THEN 90 110 Q-37*N 130 PRINT ">":REM BUZZER 140 PRINT "YOUR NUMBER IS "JQ 150 PRINT JPRINT X GOTO 20 39 Gee Whiz III: Yes/No Decision Maker This is handy for the busy executive who doesn’t have time for decisions. Line 10 clears the screen. Line 20 generates a ran¬ dom number from zero to 100. Line 30 selects a yes answer if the random number is greater than 49. Other¬ wise, line 40 chooses a no answer. Program Listing 10 PRINT "}"s REN SCREEN CLEAR 20 X=100*(RND(1)) 30 IF X>49 THEN PRINT "YES":GOTO 50 40 PRINT "NO" 50 END 56 40 Gee Whiz IV: First Alphabet Spotter There are 26 letters in the alphabet. Each has a number. For instance, number 1 is A. Number 20 is T. This Gee Whiz program has the computer ask you for a number from 1 to 26 and then, faster than a jackrabbit, tell you what letter it goes with. Naturally, you’ll know how it works but to your non¬ computer friends it will seem like the computer is a genius! Program Listing 10 PRINT ">"JREM SCREEN CLEAR 20 PRINT "GIVE ME THE NUMBER OF" 30 PRINT "A LETTER FROM THE ALPHABET" 40 PRINT "FROM 1 TO 26" 50 INPUT N 55 IF N>26 THEN 20 56 IF N<1 THEN 20 60 X ~ N+6 4 70 PRINT JPRINT * PRINT 80 PRINT "LETTER NUMBER "JN," IS "»CHR$" s REM BUZZER 140 PRINT "LETTER NUMBER ";N;" IS ";A* 150 RESTORE 160 PRINT SPRINT 170 GOTO 50 42 Gee Whiz VI: Guess The Number Here it is! The world’s oldest, longest running, most popular game: Guess The Number. When you start the program running, the computer thinks of a number and stores that away. You try to guess the number. If your number is too high, the computer says, “TOO HIGH.” If you are too low, the computer will report “TOO LOW.” The possible numbers range from zero to 100. Program Listing 10 PRINT ">"s REM CLEAR SCREEN 20 DIM Q*<1) 30 Q$="*" 40 GOTO 110 50 N=INT(101*(RND(1))) 60 PRINT "GUESS THE NUMBER",sINPUT G 70 IF G>N THEN PRINT "TOO HIGH":GOTO 60 80 IF G 40 N=INT " , M 60 IF W=3 THEN PRINT " FORGET IT !" sGOTO 1.40 70 FOR T=1 TO 500 s NEXT T 80 PRINT "}"sREM CLEAR SCREEN 90 PRINT "WHAT WAS IT"INPUT S 100 IF SOM THEN PRINT "***YOU ARE WRONG s W—W+-1 s GOT0 60 110 PRINT "YOU ARE RIGHT !":R=R+1:Z=Z*10 120 PRINT R;" RIGHT SO FAR" 130 PRINT sGOTO 30 140 PRINT SPRINT "YOU HAD ";R;" RIGHT" 150 PRINT SPRINT "LET’S START OVER" 160 PRINT "PRESS RETURN" 170 DIM K*<1) 180 INPUT K* 190 CL.R SGOTO 10 63 Number Reverser Give yourcomputerany three-digit number and,as a result of this particular programming trick, it will reverse the original number. For example, 789 will be transformed into 987. Or 123 into 321. It takes your three-digit number apart and reassembles it in reverse order. Program Listing 1(3 PRINT M >":REM SCREEN CLEAR 20 PRINT "ENTER A THREE-DIGIT NUMFFR: ■ 30 INPUT N 40 IF N-' 100 OP N>9?9 THEN 20 50 A = I NT(N/100) 60 E=INT<10*(-A)) 7© C=INT<10*((N/10>- , K$< 1 ) 30 PRINT "ENTER LETTER G RADES B M 40 INPUT G$ 50 IF G$= h y n THEN 140 80 IF G$= ” A " THEN A=A+1 : GOT 0 40 90 IF G*= 11 p »} THEN E=B+1: GOT 0 40 100 IF G$ ...» !t £*■ *| THEN C=C+1 : GOTO 40 110 IF G* = " D " THEN D=D+1 : GOTO 40 120 IF 6$ ~~ 11 p M THEN F=F +1 5 GOTO 40 130 GOT 0 H 0 140 PRINT ii \ I* :REM SCREEN CLEAR 150 PRINT "As " , A 160 PRINT " E s " , F 170 PR INI- ** ^ R " , c 180 PRINT "Ds ",D 190 PR INI- "Fs " ,F 200 PRINT sRR I NT : PRINT 210 PRINT " FO R MORE, PRES 3S RE' TURN 220 INPUT K$ 230 CL.R : GOTO 10 Sample Run ENTER LETTER GRADES A C F D B A B C C C D 65 F A: 2 B: 2 C: 4 D: 2 F: 2 Number-Error Trapping Good programs, those which are well written, need error trapping. It’s a technique for making sure persons communicating with the computer don’t key in inap¬ propriate data or make mistakes which would cause com¬ putation problems for the computer. For instance, see the example program here. In line 10 the computer asks for a number. In line 20, if the number is too low, it says so and goes back to line 10 to repeat its request. At line 30, if the number received at line 10 is too large, it says so and goes back to line 10 for a better choice. The result is only printed at line 40 when a satisfac¬ tory number has been keyed in back at line 10. You can set your own limits by changing the 10 in line 20 and the 100 in line 30. Program Listing 5 PRINT ">":REM CLEAR SCREEN 10 PRINT "GIVE ME A NUMBER INPUT A 20 IF A<10 THEN PRINT "TOO LOW":GOTO 10 30 IF A>100 THEN PRINT " TOO HIGH" :GOTO 10 40 PRINT A 66 Standard Deviation Here’s a way to determine mean and standard devia¬ tion. In this particular program, you exit the entry cycle by entering the large number 999999999 (nine 9’s) so you can’t use 999999999 as one of your data points. This is a great opportunity to experiment with standard deviation computations. Try a series of data points and the program will calculate the total number of data points, the mean, the variance and the standard deviation. Program Listing 10 PRINT ’’ } " s REM SCREEN CLEAR 20 PRINT "DATA POINTS INPUT X 30 IF x=999999999 THEN 60 40 T=T+X;S~S+ X A 2 s N=N+1 50 GOTO 20 60 A=T / N: '■■■!=S / N - A A 2 s 0=SQR (V ) 70 PRINT SPRINT 80 PRINT "DATA POINTS TOTALs",T 90 PRINT "MEAN:",,A 100 PRINT "VARIANCE:",V 110 PRINT "STD DEVIATION:",D 120 PRINT SPRINT 130 CL.R s GOTO 20 Percentages Usually it’s more convenient to enter percentages as percent rather than having to convert to decimals in your head first. Of course, the computer needs that converted decimal value to do its work. How to get it? This program does the trick. You give it a percentage 67 and it converts that to a decimal. The computer does the hard work for you! Line 30 makes the actual conversion. Use this idea as part of a larger check-balancing, accounting or bookkeep¬ ing program and save lots of mental effort. Program Listing 10 PRINT " } ":REM CLEAR SCREEN 20 PRINT ”PERCENTAGE: " : ! :INPUT 30 D=0.01 *P 40 PRINT "DECIMAL:",D 50 PRINT sGOTO 20 p Logic Functions You can make your computer do things based on its decision that something exists. That is, in the first pro¬ gram listing here, it only will print the value of C if it finds that B has an existing value. If B is found to have no value, does not exist, C will not be printed. The decision is in line 40. The machine only prints C if B does not equal zero. Since, in line 20, we set B = 10, the computer will find that something exists in B and, thus, go ahead and do the work assigned in the last half of line 40. If nothing had been stored in B, the last half of line 40 would have been ignored. Program Listing 10 PRINT ->":REM CLEAR SCREEN 20 B= 10 30 C=10*B 40 IF E THEN PRINT C In the second program, the ATARI Computer displays only the results of the tests in lines 40 and 50 if the result of one or both is “true.” By doing the simple math in your head, you can see 68 that the information in the right-hand side of line 20 is true. The information in the right-hand side of line 30 is false. Line 20 says that 6 + 8 is greater than 3 times 4. That is, 14 is greater than 12. That is true. Line 30 says that 5 + 2 is greater than 9 + 2. That is, 7 is greater than 11. That is false. After reading line 20, the computer will store a 1 in B since the statement is true. Upon reading line 30, the computer will store a zero in C since the statement is false. As action drops to line 40, the computer will find the 1 it stored in B and, thus, complete the action called for at the right-hand end of line 40. It will display the message, “B OKAY.” At line 50, however, the computer will find “nothing” (zero) in C and will not complete the right-hand end of that instruction. It only will do the right-hand end if it finds something in the left-hand end. These logic functions are great for quick tests. Program Listing 10 PRINT ">"s REM SCREEN CLEAR 20 E=(6+8)>(3*4) 30 C= ( 5+2') > (9+2) 40 IF B THEN PRINT "E OKAY" 50 IF C THEN PRINT "C OKAY" Above & Below a Line Here’s a way to count numbers above and below a cut-off line. The computer solicits numbers between 1 and 100. Any numbers you key in which are below 1 or above 100 are trapped out by line 40. Entering a zero ends the input cycle. Line 50 counts the total numbers. Line 60 counts on¬ ly those numbers between 1 and 50. Line 80 counts the numbers from 51 to 100. Lines 90 to 130 present results. 69 Program Listing 10 PRINT " }”:REM SCREEN CLEAR 20 PRINT " GIVE ME A NUMBER:INPUT 30 IF Z=0 THEN 80 40 IF Z<1 OR Z>100 THEM 20 50 N=N+1 60 IF Z<5 1 THEN B=B+1 70 GOTO 20 80 A=N-~B 90 PRINT : PRINT 100 PRINT "NUMBERS TOTAL s " , N 11.0 PRINT- ”1 TO 50"i,E 120 PRINT "51 TO 100s",A 130 PRINT SPRINT SPRINT SPRINT 140 CL..R : GOTO 20 Factoring This program finds and lists the factors of any number you specify. It can be used as a subroutine in a larger program, with appropriate attention to line numbers, variable names, and RETURN. The number of individual factors are limited by the DIM statement in line 20. The list will exclude the number itself divided by 1. For a quick sample run, try the number 18. You should find factors are 9, 6, 3 and 2. Program Listing 10 PRINT ♦ REM SCREEN CLEAR 20 DIM Q < 999) 25 FOR L“0 TO 9991Q 1 THEN PRINT Q (L.) l GOTO 120 110 Z=Z+l 120 NEXT L 150 PRINT JPRINT JGOTO 25 52 Which is Smallest? How can the computer tell which number is smaller or larger? Here’s how. Type in the program and RUN it. It will ask for, and ac¬ cept a continuous string of numbers until you end the in¬ put routine by keying in a zero. Lines 40 to 60 make the decision as to which number is lowest. Program Listing 10 PRINT " }"s REM SCREEN CLEAR 20 PRINT "GIVE ME A NUMBER:INPUT Z 30 IF Z=0 THEN 80 40 N=N+1 50 IF N=1 THEN D=Z 60 IF Z":REM CLEAR SCREEN 20 PRINT "GIVE ME A NUMBER",sINPUT Z 30 IF Z=0 THEN 60 40 IF Z>D THEN D=Z 50 GOT0 20 60 PRINT :PRINT 70 PRINT "THE LARGEST NUMBER IS "?D 80 PRINT :PRINT :PRINT :PRINT 90 CL.R : GOT0 20 Reciprocals Key in any number. The computer will display its reciprocal. The actual conversion is done here at line 30. Program Listing 10 PRINT "!"s REM SCREEN CLEAR 15 PRINT "NUMBER TO BE CONVERTED" 20 PRINT "TO ITS RECIPROCAL.: 25 INPUT N 30 R=l/N 35 PRINT :PRINT 40 PRINT "RECIPROCAL OF ";Ns" IS ";R 45 PRINT :PRINT 50 CLR SGOTO 15 72 Dump the Integer Look at the number 123.456 with an eye toward how to get rid of the portion left of the decimal point. Keep only .456 and dump 123. Here’s a short program to ac¬ complish that. Try 5.67. It will come out .67. Or 500.5 which will come out .5. Program Listing 10 PRINT "}":REM SCREEN CLEAR 20 PRINT "GIVE ME A NUMBER" 30 PRINT "WITH A DECIMAL:" 40 INPUT N 50 X=N—INT(N) 60 PRINT 70 PRINT "THE FRACTIONAL. PORTION" 80 PRINT "OF ";N5" IS ";X 90 PRINT :PRINT :PRINT :PRINT 100 CL R s GOTO 20 Averages Key in numbers in any order. A zero will end entry. The computer will tell you the average number of all numbers you entered. Line 40 finds the total number of all numbers entered. Line 50 finds the total of entered numbers. Line 70 computes the average. Program Listing 10 PRINT "}"SREM CLEAR SCREEN 20 PRINT "GIVE ME A NUMBER”INPUT Z 30 IF Z=0 THEN 70 40 N=N+1 73 5® T=T+Z 60 GOTO 20 70 A=T/N 100 PRINT :PRINT 110 PRINT "THE AVERAGE IB ";A 120 PRINT SPRINT SPRINT SPRINT 130 CLR SQOTO 20 Mid-Range Number Here’s how to find the middle of a range of numbers. You key in as many numbers in a series as you wish. After the last number, key in a zero to move the program out of the entry cycle. Lines 40 to 70 select the highest and lowest numbers in the range. They actually define the range. Then line 90 finds the middle point of that range. Program Listing 10 PRINT "}"sREM SCREEN CLEAR 20 PRINT "GIVE ME A NUMBER",sINPUT Z 30 IF Z=0 THEN 90 40 N=N+1 50 IF N=1 THEN H=ZsL=Z 60 IF ZH THEN H=Z 80 GOTO 20 90 M=L+( ( H~L)/2) 100 PRINT SPRINT 110 PRINT "MID-RANGE NUMBERS",M 120 PRINT SPRINT SPRINT SPRINT 130 CLR sGOTO 20 Rounding Off The technique for rounding off numbers is easy. 74 This program, which can stand alone or be worked into a larger program as a subroutine, rounds a decimal to the nearest whole number. There are two views on how to round off. One holds that “if the number is more than five, you round up.” Which means that exactly 0.5 rounds down. Another view is that “any number less than five rounds down.” In that case exactly 0.5 rounds up. The first set of program lines below is for the fellow with the “more than five rounds up” idea. Program Listing 10 PRINT "l":REM SCREEN CLFAR 20 PRINT "GIVE ME A NUMBER" 30 PRINT "TO BE ROUNDED OFF" 40 INPUT N 50 IF N>INI(N) THEN 80 60 R=N 70 GOTO 3.30 80 D=N--INT CN> 90 IF D>0.5 THEN 120 100 R=INT(N > 110 GOTO 130 120 R= I NT < N) + 3. 130 PRINT ">”:REM BUZZER 140 PRINT Ni" ROUNDS OFF TO ";R 150 PRINT SPRINT SPRINT 160 CLR s GOT0 20 The second set of program lines rounds off on the “less than five rounds down” theory. Program Listing 10 PRINT "}"sREM SCREEN CLEAR 20 PRINT "GIVE ME A NUMBER" 30 PRINT "TO EE ROUNDED OFF" 40 INPUT N 50 IF N>INT":REM CLEAR SCREEN 20 FOR L=1 TO 100 30 X=INT <100*(RND(1)) ) 40 IF X<50 THEN Y=Y+1 50 IF X>49 THEN N=N+ 3 . 60 NEXT L. 70 PRINT Y;" YES" 80 PRINT N;" NO" 90 PRINT 'PRINT 5 PRINT 100 CLR ;GOTO 20 Sample Run 51 YES 49 NO 42 YES 58 NO 56 YES 4.4 NO 46 YES 54 NO 52 YES 48 NO 48 YES 52 NO Random Numbers: Zero To Nine Although you see four program lines below, what we really have here is a very convenient single-line program 78 for you to insert in a larger game or educational-testing program. Line 20 is the winner here. It prints a random number from zero to nine every time. For your use here, we print that number on the screen. You could just as easily have the computer store that random number in a memory location for later recall and use. We have added lines 10, 30 and 40 to make your ATARI Computer show a series of random numbers from zero to nine. Remember, line 20 is the important single- line program element here. If you would like random numbers in the range from zero to 99, make it 100* in line 20. For zero to 999, use 1000* in line 20. Program Listing 10 PRINT "}"5 REM SCREEN CLEAR 20 PRINT INT(10* < RND <1))) 30 FOR L=1 TO 200:NEXT L 40 GOTO 20 Random Numbers: Distribution Ever wonder how “random” are the numbers generated by the random-number generator in your ATARI Computer when you use the RND instruction? Try this program. It generates 100 random numbers in a range from zero to nine and counts how many there are of each number between zero and nine. By the way, while it is doing that it will display the message “counting” so you can tell it is working. At the end of its run, the computer prints a chart, on the video display, of results. See our sample run. Program Listing 10 PRINT ">“:REM SCREEN CLEAR 79 20 FOR L=1 TO 100 30 N=I NT(10*(RND( 1 ) ) ) 40 IF N=0 THEN A=A+1 50 IF N=1 THEN B=B+1 60 IF N=2 THEN C=C+1 70 IF N=3 THEN D=D+1 80 IF N=4 THEN E=E+1 90 IF N=5 THEN F=F+1 100 IF N=6 THEN G=G+1 110 IF N=7 THEN H=H+1 120 IF N=8 THEN 1=1+1 130 IF N=9 THEN J=J+1 140 PRINT "COUNTING" 150 NEXT L 160 PRINT " } ” s REN CLEAR SCREEN 170 PRINT " > " 'REM EUZZER 200 PRINT "0" i A 210 PRINT " 1" 1 B 220 PRINT II 2 H , C 230 PRINT „ 3" i D 240 PRINT "4" i E 250 PRINT "5" ,F 260 PRINT "6" i G 270 PRINT it y »» ,H 280 PRINT n B" » I 290 PRINT II ty H 300 END Sample Run RUN RETURN COUNTING 0 8 1 10 2 14 3 16 4 6 5 7 6 7 7 15 80 8 4 9 13 RUN RETURN COUNTING 0 6 1 12 2 11 3 13 4 7 3 12 6 9 7 10 8 8 9 12 Random Numbers: Averages This program generates 100 random numbers and totals them. Then it finds the average of all 100 numbers. In fact, the average number itself is a useful new ran¬ dom number. To make the program run again, press the RETURN key on the computer’s keyboard. Program Listing 10 PRINT ">":REM CLEAR SCREEN 20 FOR L=0 TO 99 30 N= I NT < 10* < RND < 1 ) ) ) 40 NT-NT+N 50 PRINT "AVERAGING" 60 NEXT L 70 PRINT "}":REM SCREEN CLEAR 80 AV=NT./ 100 90 PRINT "TOTAL OF 100 RANDOM NUMBERS" 100 PRINT "BETWEEN ZERO AND NINE IS "?NT 81 110 PRINT "AVERAGE IS ";AV 200 DIM K$<1> 210 PRINT "FOR MORE, PRESS RETURN" 220 INPUT K$ 230 CL.R sGOTO 10 66 Random Numbers: Sorting High/Low It’s important to be able to sort a group of numbers to see what the highest and lowest values are. This program does that. The random number generator is in line 30. It gives numbers in a range of zero to 999. Line 50 determines the lowest number in the set and line 60 finds the highest number. Program Listing 10 PRINT ">”:REM SCREEN CLEAR 20 FOR L=0 TO 99 30 N=INT(1000*(RND(1))) 40 IF L=0 THEN LN=N:HN=N 50 IF NHN THEN HN=N 70 PRINT "SORTING" 80 NEXT L 90 PRINT CHR$(253):REM EUZZER 100 PRINT ">"5 REM CLEAR SCREEN 110 PRINT "LOW NUMBER IS ",LN 120 PRINT "HIGH NUMBER IS ",HN 200 END Sample Run RUN RETURN SORTING 82 LOW NUMBER IS 32 HIGH NUMBER IS 983 LOW NUMBER IS 14 HIGH NUMBER IS 980 LOW NUMBER IS 17 HIGH NUMBER IS 985 LOW NUMBER IS 9 HIGH NUMBER IS 991 LOW NUMBER IS 1 HIGH NUMBER IS 994 83 Money Matters Money Grows This section of the book includes a number of pro¬ grams relating to household money management and to small-business applications. This first program shows you how your money grows when deposited in a savings account at a certain annual interest rate, compounded monthly. The program will have the computer ask for the initial amount of principal saved by depositing in the account. Then the annual interest rate and the number of months to be displayed. The result of the run is a display of the changing principal as months pass and interest is added on. Line 10 clears the text screen. Lines 20 and 40 take in data from you. Lines 50 to 90 put out the results. Very handy! Program Listing 10 F 'RINT ">" f REM CLEF \R SC REEN 20 F RINT "PRINCIF •AL i 1 * f ♦ INPUT P 30 r ’RINT "ANNUAL inti: IRE ST RATE %",:INPUT 4 0 F 'RINT "NUMBER OF MON TH 8" , t X INPUT M 50 F OR Q = 1 TO M 6 0 I > JINF UT i <* 130 CLR X GOTO 10 Shopper’s Friend This program finds the computer asking for certain 86 information and then telling you which product brand name is the best buy. The computer will ask for the brand name of a product, the quantity in the product package, and the price of the package. Then it will ask for the name, quantity and price for a second product. After digesting all this information, it will tell you the brand name of the best-buy product and show you the unit prices for both brand names so you can agree with the computer’s judgment. For example, suppose you were looking at corn flakes in boxes, one by Post and one by Kellogg. Suppose the Post box contained 24 ounces of flakes and was priced on the grocery shelf at $1.98 while the Kellogg box held 18 ounces and was priced at $1.59. Which would be the better buy based on unit price per ounce of flakes? Run the data through your computer and you’ll find it computes the Post corn flakes to be the best buy with a unit price of 84 vs. the Kellogg unit price of 94. By the way, if the unit prices turn out to be equal, the computer will say they are equal. Program Listing 10 PRINT "}";REM SCREEN CLEAR 20 DIM X$<20>,Y$<20>,K$<1) 30 PRINT " SHOPPER’S FRIEND" 40 PRINT "FIRST BRANDsINPUT X$ 50 PRI NT "QUANTITY:", :INPUT M 60 PRINT "PRICE;",INPUT N 70 PRINT "SECOND BRANDINPUT Y* 80 PRINT "QUANTITY:",:INPUT Q 90 PRINT "PRICE:INPUT R 100 IF N/M=R/Q THEN 500 110 IF N/li"sREM CLEAR SCREEN 20 DIM K$ < 1 > 30 FOR L=1 TO 38:PRINT "*";:NEXT L 40 PRINT "* AUTOMOBILE. PAYMENT *" ; 50 FOR L-1 TO 38:PRINT “*";:NEXT L 60 PRINT "PURCHASE PRICE INPUT T 70 PRINT "DOWN PAYMENT INPUT R 80 PRINT "NUMBER OF MONTHS:INPUT N 90 PRINT "ANNUAL INTEREST INPUT I 100 I =< 0 . 01*1)/12 110 P=(T-R)*I/(1-1/<1 + 1) A N) 120 PP=INT<100*P+0.5>/100 130 PRINT :PRINT "PAYMENT PP 140 FOR L=1 TO 38:PRINT H *"?sNEXT L 150 PRINT :PRINT 160 PRINT "FOR MORE, PRESS RETURN" 170 INPUT K$ 180 CLR :GOTO 10 88 To Nearest 95 Cents Many companies like to price their goods at a figure ending in 95 cents. For instance, a ten dollar item might be marked $9.95 or $10.95. Here’s a program which demonstrates how to make all prices come out to the nearest 95 cents. See line 40. It merely takes the integer portion of the dollars number and adds 0.95 to it. Program Listing 10 PRINT "}":REM CLEAR SCREEN 23 PRINT "MANUFACTURING COST= $":INPUT 30 PRINT "PRICING MULTIPLIER™ INPUT M 40 P=I NT(C*M}+0.95 50 PRINT 60 PRINT "RETAIL PRICE= $";F 70 PRINT :PRINT 80 CLR :GOTO 20 Sample Run MFG COST = $ 1.12 RETURN PRICING MULTIPLIER = 10 RETURN RETAIL PRICE = $11.95 RETURN To the Nearest Penny This program is useful when you have a dollar-and- cents figure with more than two decimal places. For ex¬ ample, $151.6972. You need to transform $151.6972 to the more common $151.70 This small program would make a good subroutine in 89 a larger set of instructions. To do so, insert GOSUB at the appropriate place in the larger set of program lines. Modify the line numbers of this small program so the subroutine will be located in an unused position in the larger listing. Change the last line of this small program to RETURN. Delete the first line. Program Listing 10 PRINT " )■ " : REM CLEAR SCREEN 20 PRINT "ENTER A NUMBER TO" 30 PRINT "MORE THAN TWO DECIMAL PLACES" 40 PRINT :PR I NT "ORIGINAL AMOUNT = "; 50 INPUT N 60 R=I NT<100*N+0.5)/100 70 PRINT SPRINT "TO THE NEAREST PENNY,” 80 PRINT "*";N;" IS $";R 90 PRINT SPRINT 100 CLR s GOT0 40 72 Mark Up Mr. Storekeeper, here’s just what you have needed to compute mark ups. With this program, your computer will determine your retail price, based on your required mark up over wholesale cost. For instance, if you mark up an item by 40 percent and paid $60 wholesale, how much will your retail price be? The answer is $84. To put it another way, 40 percent of $60 is $24; adding this $24 to your wholesale cost of $60 gives you a re¬ tail price of $84. Try $40 wholesale cost which you want to mark up 60 percent. The answer is $64 retail. Or try $10 wholesale with 10 percent mark up. The retail price would be $11. Here’s a toughie! Try $19.95 wholesale cost. The mark up percentage you require is 40. The correct retail price is $27.93. 90 Program Listing 10 PRINT JREM CLEAR SCREEN 20 PRINT "WHOLESALE COST VJINPUT W 30 PRINT "MARK-UP PERCENTAGE %"$INPUT P 40 D-1 + 0 ♦ 0:Up;R~W*D 50 PRINT "RETAIL PRICE - $" JR 60 PRINT I PRINT 70 CLR JGOTO 20 Percentage Off From earlier tips in this book, you know how to make your computer convert percentages to decimals. But what if you want to know “percentage off”? For example, how much is 40 percent off? This pro¬ gram can be used to interpret 40 percent off and compute the decimal value needed. Try 40 percent off $100. The computer will change 40 percent off into decimal value 0.60. If you multiply 0.60 times $100 you find $60 is 40 per¬ cent off $100. Line 50 makes the important translation. Program Listing 10 PRINT “}":REM SCREEN CLEAR 20 PRINT "LIST PRICE $":INPUT L 30 PRINT "PERCENTAGE OFF X":INPUT P 40 PRINT ”>":REN CLEAR SCREEN 50 D=1—0.01*p 60 PRINT "TO COMPUTE WITH ";Ps"v OFF" 70 PRINT "THE DECIMAL WILL BE ";D 80 PRINT 70 PRINT P; " 7. OFF $";L 100 PRINT "RESULTS IN A COST OF *";D*L 110 PRINT : PRINT 120 CLR sGOT0 20 91 74 Dollars & Cents If the result of your computation is a “money" answer, and you don’t know whether to display it in dollars or cents, let the computer decide. This program decides whether to display the output in dollars or cents. Line 50 in the program makes the decision. Program Listing 10 PRINT ">":REM SCREEN CLEAR 20 PRINT "QUANTITY s", :INPUT P 30 PRINT "TOTAL COST INPUT C 40 T=C/P 50 IF T<1 THEN T=100*T 5 GOTO 80 60 PRINT "EACH COST *";T 70 PRINT :PRINT :CLR sGOTO 20 80 PRINT "EACH COST ";T;" CENTS" 90 PRINT "-PRINT sCLR sGOTO 20 75 Wages & Hours These useful lines compute total hours worked at regular pay and number of hours worked at time-and-a- half overtime. The computer then finds gross pay and rounds off to the nearest cent. The program knows that overtime starts after 40 hours. It makes payroll bookkeeping quick and simple. Program Listing 10 PRINT "}"s REM SCREEN CLEAR 20 PRINT "HOURLY PAY RATE = INPUT P 30 PRINT "NUMBER HOURS WORKED = INPUT H 40 IF H>40 THEN OT=H-40:GOTO 100 92 50 W=H*P 60 PRINT "GROSS WAGEE3 ==" , " $ M 5IJ 70 END 100 W~ ( 40 *P ) -I-- ( OT*P* 1,5) 11 0 Go TO -60 Sample Run RUN RETURN HOURLY PAY RATE = $ 5.75 RETURN NUMBER HOURS WORKED = 61 RETURN GROSS WAGES = $411,125 Invoicing There’s a lot of repetitious math work to be done before you mail invoices to your customers. This software has the computer collect a few pertinent bits of data from you and then present all the various totals you need to plug in¬ to an invoice. It gives you a total retail price for all goods sold on the invoice, total sales tax if applicable, shipping charges and the grand total amount due you from your customer. Program Listing 10 PRINT ">":REM SCREEN CLEAR 20 PRINT "QUANTITY SOLD",:INPUT 0 30 PRINT "UNIT PRICE = INPUT P 40 PRINT "SALESTAX RATE PERCENT*"INPUT S 50 PRINT "SHIPPING CHARGES = *INPUT H 60 S=0„01*S:C=Q*P:T=C*S:F-C+T+H 70 CC=INT<100*C+0„5)7100 80 TT=INT(100*T+0.5)/100 90 FF=INT <100*F+0„5 ) / 100 100 PRINT ">":REM CLEAR SCREEN 93 110 PRINT "TOTAL PRICE = $";CC 120 PRINT "SALES TAX = *"STT 130 PRINT "SHIPPING CHARGES = $";H 140 PRINT 150 PRINT "INVOICE TOTAL = $”;FF 20(3 END Sample Run RUN RETURN QUANTITY SOLD 178 RETURN UNIT PRICE = $ 53.98 RETURN SALES TAX RATE PERCENT = 6 RETURN SHIPPING CHARGES = $ 100 RETURN TOTAL PRICE = $9964.44 SALES TAX = $597.87 SHIPPING CHARGES = $100 INVOICE TOTAL = $10662.31 Unit Price Suppose you find 895 green Widgets and buy them for $695. How much did each green Widget cost? Rounded off, 78 cents. Unit price is total price divided by quantity. The quanti¬ ty can be expressed in weight, total numbers, etc. It works the same whether you are talking about pounds of coffee, yards of concrete, gallons of ice cream, boxes of books, or units of Widgets. This program asks for the name of the item, quantity purchased and total price paid. It then displays quantity, name, total and unit price. 94 Program Listing 10 PRINT "j":REM SCREEN CLEAR 20 DIM N$(20),K$(1) 30 PRINT "ITEM NAME IS "sINPUT N$ 40 PRINT "QUANTITY OF ITEMS = "sINPUT 0 50 PRINT "TOTAL PRICE PAID FOR ITFMS $" 60 INPUT P 70 U=P/Q 80 UU=INT(100*U+0.5)/100 90 PRINT " >" :REM BUZZER 100 PRINT N$;" UNIT PRICE = $";UU 110 PRINT :PRINT :PRINT 120 PRINT "TO DO MORE, PRESS RETURN" 130 INPUT K$ 140 CLR :GOTO 10 Sample Run RUN RETURN ITEM NAME IS WIDGETS RETURN QUANTITY OF ITEMS = 999 RETURN TOTAL PRICE PAID FOR ITEMS = $ 14653 RETURN BEEP WIDGETS UNIT PRICE = $14.67 Inventory Counter The computer makes it very convenient to tally the number of items in your inventory. This workaholic program is set up for up to ten different inventory items. You code them with the numbers 1 through You may enter any quantity for any item code in any mixed sequence. You may repeat item codes and add to quantities as often as you like. 95 When you finish entering quantities, enter a zero in response to the “item code” query. The computer will respond with a display of grand totals for each of the ten item codes. Here’s the routine: Line 20 asks for the item code number from one through 10. If you enter a zero, action jumps to line 70 for a display of grand totals. Otherwise, the computer proceeds to line 40., You are limited to item-code responses from zero through ten. If you try to enter a number larger than 10, the computer will discover that via the test in line 40 and ship the whole operation back to line 20 where it asks you again for a valid number. If, at line 40, it finds a valid item code number from one to ten it will allow the execution to go on to line 50. At line 50, the computer asks for the quantity of the item. Line 60 causes the computer to jump to the appro¬ priate line to add that quantity to the various item totals. Note that the portion of the program from line 201 through line 210 has line numbers stepping up by ones rather than the conventional tens. This is because of the way line 60 jumps. It takes the item code number from one through ten and adds that to 200 to create a number from 201 to 210. It then jumps to that number. Suppose your item code was 5. The computer would add 5 to 200 and get 205. It then would.jump to line 205. A neat sorting trick! Each of thelines201 through210endwithajumptoline 20. This allows you to continue to enter item codes and quantities as long as you like. When you finish, enter zero for item code and line 30 will push action to line 70. At line 70, the computer finds instructions, through line 90, to display the grand totals. Lines 100 to 130 ask if you want to do more. To make the program run again, press the RETURN key on the computer’s keyboard. Program Listing 10 PRINT ">":REM SCREEN CLEAR 20 PRINT "ITEM CODE: INPUT C 30 IF C=0 THEN 70 96 40 IF 01(3 THEN 20 50 PRINT "QUANTITY: ",:INPUT 0 60 GOTO C+200 70 PRINT ">":REM CLEAR SCREEN 80 60SUB 300 100 PRINT :PRINT "FOR MORE,PRESS RETURN" 110 DIM KIN) 120 INPUT K$ 130 CLR :GOTO 10 201 J--J+0: GOTC> 20 202 K--K+0: GOT0 20 203 L= : L+0 : GOT0 20 204 M=M+Q!GOTO 20 205 N=N+0:GOTO 20 206; R “ R+Q : G 0 T 0 2 0 207 S--S+Q : GOT0 20 208 T = : T+0 : GOTO 20 209 U--U+Q : GOT>0 20 210 V=U+0:GOTO 20 22(3 END 300 PRINT ”l:",J 31© PRINT "2:" , K 320 PRINT "3:",L 330 PRINT ”4:",M 340 PRINT "5:",N 350 PRINT "6:",R 360 PRINT "7:",S 370 PRINT ”8:" ,T 380 PRINT " 9 : " , U 390 PRINT "10:",V 400 RETURN 79 Daily Code Need to have a secret code each day of the year? This software generates a list of code numbers. Of course, you can change the list every day if you wish. 97 Program Listing 10 PRINT ">":REM SCREEN CLEAR 20 GOSUB 200 100 PRINT "SUNDAY:C:GOSUB 200 110 PRINT "MONDAY:",,CsGOSUB 200 120 PRINT "TUESDAY:",,C:GOSUB 200 130 PRINT "WEDNESDAY:",C*GOSUB 200 140 PRINT "THURSDAY:",C:GOSUB 200 150 PRINT "FRI DAY:",,C:GOSUB 200 160 PRINT "SATURDAY:",CsEND 200 C=INT <10000* < RND(1))) 210 IF CC1000 THEN 200 220 RETURN 98 Colorful Graphics 80 Aztec Art In this Colorful Graphics section of the book, you will find a number of interesting new and different applica¬ tions for the graphics capabilities of the ATARI computer. These can be modified, combined or otherwise changed to suit your own needs. Our titles represent only the thoughts we had when we watched these programs run. You might like to dream up new and different titles for your own creations made by modifying these programs. Colors can be changed. Screen locations can be changed. Movement can be reversed. Try all of these pro¬ grams. You’ll like them! Our first program reminded us of Aztec artwork. Program Listing 10 GRAPHICS 3+16 20 FOR L-1 TO 0 STEP -1 30 FOR N=1 TO 12 40 COLOR L. 50 PLOT 20,10 60 X=20-(10*COS ":REM BUZZER 20 GRAPHICS 10 30 POKE 704,96 40 POKE 705,22 104 50 POKE 706,38 60 POKE 707,54 70 POKE 708,70 80 POKE 709,86 90 POKE 710,104 100 POKE 711,120 110 POKE 712,180 120 FOR X=1 TO 64 130 LL.= 191 —X : LR=79-X 140 M=M*(M<8)+1 150 COLOR M 160 PLOT X,X 170 DRAWTO X , L.L 180 DRAWTO LR,LL 190 DRAWTO LR,X 200 DRAWTO X,X 210 NEXT X 220 A=PEEK(712):E=PEEK(711):C=PEEK(710) 230 D=PEEK(709):E=PEEK(708):F=PEEK< 707) 240 5=PEEK(706):H=PEEK < 705) 250 POKE 712, E 260 POKE 711 , c 270 POKE 710, D 280 POKE 709, E 290 POKE 708, F 300 POKE / 0 /, G 310 POKE 706, H 320 POKE 705, A 330 GOTO 220 NOTE: Requires revised GTIA chip to run correctly. Super Moving Illusion If you liked Tip Number 84 above, you’ll love this one! Here the background color changes as well as the color of the lines. Very striking! 105 Program Listing 10 PRINT REM BUZZER 20 GRAPHICS 10 30 POKE 704,96 40 POKE 705,22 50 POKE 706,38 60 POKE 707,54 70 POKE 708,70 80 POKE 709,86 90 POKE 710,104 100 POKE 711*120 110 POKE 712,180 120 FOR X-l TO 64 130 LL«191-X:LR=79-X 140 M=M*(M<8>+1 150 COLOR M 160 PLOT X,X 170 DRAWTO LR,X 180 DRAWTO L..R, LL 190 DRAWTO X,LL 200 DRAWTO X,X 210 NEXT X 215 J-96 220 A-PEEK(712) 5 8-PEEK (711 > ♦ C-PEEK (710) 230 D-PEEK( 709)JE-PEEK < 708) l F-PEEK(707) 240 G-PEEK(706)JH-PEEK(705) 250 POKE 712,B 260 POKE 711,C 270 POKE 710 , D 280 POKE 7 0 9 , E 290 POKE 708,F 300 POKE 707,G 310 POKE 706,H 320 POKE 705,A 330 U-,1+1 340 POKE 704,J 350 IF ,1-255 THEN J-l 360 GOTO 220 NOTE: Requires revised GTIA chip to run correctly. 106 The Seamstress It’s either somebody sewing or a spider weaving a web or something... Program Listing 10 GRAPHICS 8+16 20 COLOR 255 30 PLOT 160,96 40 X = INT(320*< RND(1)) ) 50 V-1 NT <192*(RND <1) )) 60 DRAWTO X,Y 70 GO TO 40 Swimming Fish Here’s another interesting demonstration of your ability to erase images from the screen. The erasing of the fish, here, creates an illusion of motion across the screen. The fish appears, swims right to left across the screen, and concludes with an end of swim message. Program Listing 10 GRAPHICS 8+16 20 X=319 s Y=96 30 COLOR 0 40 PLOT X--20, V 50 DRAWTO X-10,V-10 60 DRAWTO X,Y+10 70 DRAWTO X-10,Y 80 DRAWTO X,Y—10 90 DRAWTO X-10,Y +10 100 DRAWTO X-20,Y 110 X=X-10 120 IF X<21 THEN 300 130 COLOR 255 107 140 PLOT X-20,Y 150 DRAWTO X-10n Y—10 160 DRAWTO X,Y+10 170 DRAWTO X~10,Y 1S0 DRAWTO X,Y~10 190 DRAWTO X-10,Y+10 200 DRAWTO X-20,Y 210 GOTO 30 300 PRINT "END OF SWIM" Circling Dot More round graphics on your rectangular picture tube. Program Listing 10 GRAPHICS 3+16 20 FOR N-1 TO 12 30 COLOR 1 40 PLOT 20,10 50 X=20-<10*COS38 THEN 150 170 Y=INT<24*(RND<1))) 109 THEM 170 180 IF V<1 OR Y>22 190 PLOT X,Y 200 GOTO 130 Horn-In-Funnel Art The background color keeps changing. Program Listing 10 GRAPHICS 10 20 FOR Z=1 TO 96 STEP 5 30 POKE 704,Z 40 POKE 705,22 50 POKE 706,33 60 POKE 707,54 70 POKE 708,70 80 POKE 709,86 90 POKE 710,104 100 POKE 711,120 110 POKE 712,180 120 FOR X=1 TO 64 130 LL=191—XSLR=79-X 140 C=C* < C<8) +1 150 COLOR C 160 PLOT X,X 170 DRAWTO X,LL 180 DRAWTO LR, L..L 190 DRAWTO LR, X 200 DRAWTO X, X 210 NEXT X 220 NEXT Z 230 GOTO 230 NOTE: Requires revised GTIA chip to run correctly. Blackboard This program appears to draw a blackboard on the screen. You can write messages on it, draw football plays, 110 etc. Use PLOT and DRAWTO to create art or words on this electronic chalkboard by adding lines after line 90 and moving line 100 to the end of the program (don’t forget to re¬ number line 100). Program Listing 10 GRAPHICS 10 20 POKE 704,112 30 COLOR 255 40 PLOT 70,100 50 DRAWTO 70, 10 60 DRAWTO 10, 10 70 POSITION 10,100 80 POKE 765,1 90 XIO 18,#6,0,0,"S:" 100 GOTO 100 NOTE: Requires revised GTIA chip to run correctly. Snowfall White flakes sprinkle down the screen, over and over—until you press the BREAK key. It may be useless but it’s a lot of fun to watch! Program Listing 10 GRAPHICS 3+16 20 FOR L=1 TO 84 30 PRINT #6,"*"; 40 NEXT L. 50 GRAPHICS 0 60 GOTO 10 Making Things Move Movement on the computer display screen is an illu¬ sion. As in any television picture, the turning on and turn¬ ing off of dots in a pattern across a screen can seem to provide motion to an object drawn on the face of the tube. Ill There are a number of ways to get the look of motion. Let’s send a dot across the screen: Program Listing 10 GRAPHICS 3+16 20 FOR X=0 TO 39 30 COLOR 65 40 PLOT X,10 50 FOR 7-1 TO 50:NEXT T 60 COLOR 0 70 PLOT X,10 80 NEXT X 90 GOTO 20 Draw A Box Line 10 establishes the graphics screen. Line 20 sets the background color. Lines 30 to 70 draw a box. Line 100 is a freeze-frame device. Now you know how to draw a box! Program Listing 10 GRAPHICS 10 20 POKE 704,96 25 COLOR 255 30 PLOT 10,10 40 DRAWTO 70,10 50 DRAWTO 70,100 60 DRAWTO 10,100 70 DRAWTO 10,10 100 GOTO 100 NOTE: Requires revised GTIA chip to run correctly. Luminance Demonstrator Take a look at 16 shades of a color! 112 Line 10 selects graphics mode 9 which permits 16 shades of a color. Line 20 sets the background to the color desired. We have selected purple for this example. The FOR/NEXT loop in lines 30 to 70 causes the com¬ puter to run through the shades. Line 40 selects the shade. Line 50 draws the screen pattern. Line 80 is a freeze frame to hold the picture. Program Listing 10 GRAPHICS 9 20 SETCOLOR 4,6,0 30 FOR X=0 TO 15 40 COLOR X 50 PLOT X,0 60 DRAWTO X,191 70 NEXT X 80 GOTO 80 NOTE: Requires revised GTIA chip to run correctly. Draw A Line It may be an odd way to achieve-the goal but these programs draw a line across the screen. The first program below paints from top to bottom down the screen from left to right, leaving a dark horizontal line at about the middle of the screen. Program Listing 10 GRAPHICS 3+16 20 FOR X-0 TO 39 25 FOR Y=0 TO 23 30 COLOR 65 40 PLOT X,Y 50 FOR T=1 TO 50:NEXT T 60 COLOR 0 70 PLOT X,10 75 NEXT Y 80 NEXT X 90 GOTO 90 113 The second program, below, paints left to right and then downward, leaving the same dark horizontal line across the screen. Program Listing 10 GRAPHICS 3+16 15 FOR Y~0 TO 23 20 FOR X=0 TO 3? 30 COLOR 65 40 PLOT X,Y 50 FOR T=1 TO 50:NEXT T 60 COL.'OR 0 70 PLOT X,10 80 NEXT X 85 NEXT Y 90 GOTO 90 Flashing Graphics Cursor Use this flashy little indicator to spot whatever you like on the graphics screen. Change the size of the cursor spot by changing the ranges of X and Y values in lines 1030 and 1040. Program Listing 1000 GRAPHICS 10 1010 FOR L=1 TO 8 1020 COLOR L 1030 FOR X = 10 TO 12 1040 FOR Y=10 TO 20 1050 PLOT X,Y 1060 NEXT Y 1070 NEXT X 1080 NEXT L 1090 GOTO 1010 NOTE: Requires revised GTIA chip to run correctly. 114 99 Boxed Title Here’s a neat, different way to place a box around a program title—or anything else you might like to highlight. Line 10 selects graphics mode 2. The + 16 makes it full-screen. Lines 20 and 30 position and print the title. Lines 40 to 80 create the box around the title. Line 100 is a freeze- frame loop, used here so you can review your handywork. Program Listing 10 GRAPHICS 2+16 20 PRINT *6 SPRINT #6♦PRINT #6 30 PRINT *6J" TITLE" 35 COLOR 3 40 PLOT 1*1 50 DRAWTO 19,1 60 DRAWTG 19,5 70 DRAWTO 1,5 80 DRAWTO 1,1 100 GOTO 100 Draw Bar Graphs Drawing graphs on the video screen are a popular form of communication today. This program establishes a bar graph on the ATARI Computer display. We have selected the business-like example, shown here, to demonstrate how you go about setting up a bar graph on the TV screen. Lines 10 to 50 are used to input data needed to be graphed. We have selected annual profits as the subject for our graph. Line 10 asks for total profits in the year 1978; line 20 for 1979; etc. For the purposes of our graph, the maximum value you can enter will be 13. When the computer asks for the annual-profits data, give it numbers from 1 to 13. 115 Line 100 establishes full-screen graphics mode number 2. Lines 120 and 130 print the heading. Lines 200 to 230 create the first-year bar on the graph. Lines 300 to 330 create the second-year bar, and so on through line 630 which concludes the last-year bar on the graph. Line 1000 is a freeze frame to hold the picture on the screen for you to see. Press BREAK to interrupt the freeze-frame loop. Program Listing 10 F •PINT "1978 PROF its:", : INPUT A 20 F ‘PINT "1979 PROF its: n , : INPUT B 30 F •PINT "1980 PROF its: ••, : INPUT C 40 F ■PINT "1981 PROF its:", {INPUT D 50 F •PINT "1982 PROF its:", {INPUT E 100 GRAPHICS 2 •+* 16 110 COLOR 8 120 PRINT *6?" PROF ITS" 130 PRINT #6 20 0 PRINT #6;" 1978" 210 PLOT 6,2 220 DRAWTO 6+A ,2 230 POSITION 0 ,4 30 0 PRINT #6?" 1979" 310 PLOT 6,4 320 DRAWTO 6+B ,4 330 POSITION 0 , 6 "fOO PRINT #6?" 1980” 410 PLOT 6,6 420 DRAWTO 6+C,6 430 POSITION 0,8 500 PRINT #6?"1981" 510 PLOT 6,8 520 DRAWTO 6+0,8 530 POSITION 0,10 600 PRINT *6?"1982" 610 PLOT 6,10 620 DRAWTO 6+E,10 630 POSITION 0,12 1000 GOTO 1000 116 Sample Run PROFITS 1978 ((((((( 1979 (((( 1980 ((((((((( 1981 (((((((((((( 1982 (((((((((((((((( Background Cycler Need a fast way to review the various background colors available on the graphics screen? This program uses graphics mode 10 and cycles thtough the many background colors. The appropriate background color is POKE’d into memory location 704 at line 1020. The FOR/NEXT loop in lines 1010 to 1040 causes the cycling through the background-color numbers. Line 1030 is a time-delay loop, placed there to allow you to study each color briefly before it is replaced by a new color. To add more delay, increase the number 100 in line 1030. To speed things up, decrease the number 100 in line 1030. Program Listing 1000 GRAPHICS 10 1010 FOR L.= 15 TO 255 STEP 16 1020 POKE 704, L. 1030 FOR T=1 TO 100:NEXT T 1040 NEXT L 1050 GOTO 1010 NOTE: Requires revised GTIA chip to run correctly. 117 Appendix Appendix A: ATARI BASIC Words Here is a handy list of all the words in the ATARI Com¬ puter version of the BASIC computer language: ABS ADR AND ASC ATN BYE CLOAD CHR$ CLOG CLOSE CLR COLOR COM CONT COS CSAVE DATA absolute value function string memory address function logical expression true only if both are finds ASCII character number arctangent leave BASIC; write directly on screen load program from tape converts ASCII number to character base 10 logarithm close file at end of I/O job undimensions strings and arrays select color register for graphics same as DIM continue, after BREAK or STOP cosine sends data from computer to tape stores info in program line 121 DEG switch to trig degrees from radians DIM reserves memory for array or string DOS displays disk menu DRAWTO draws line between points END concludes a program run ENTER input data or programs EXP e to a power FOR sets range of FOR/NEXT loop FRE shows remaining available memory GET input single byte of data, with disk GOSUB branch to subroutine GOTO branch to a line GRAPHICS selects graphics mode IF decision maker INPUT stops for keyboard input of data INT portion of number left of decimal LEN number of characters in a string LET optional; assigns value to variable LIST display contents of program memory LOAD send program from disk to computer LOCATE stores specific graphics point LOG natural logarithm LPRINT print on paper with line printer NEW erase all program and data memory NEXT other half of FOR/NEXT loop NOT not true = 1; true =0 NOTE used with disk ON use with GOTO or GOSUB branches OPEN opens a file for I/O OR if either true, a 1; 0 if both false PADDLE position of game paddle PEEK look in one memory location PLOT light a single dot on video screen POINT for disk operations POKE put info in one memory location POP abnormal departure from GOSUB loop POSITION move to specific video screen point PRINT causes output from the computer PTRIG status of trigger button on paddle PUT output one data byte from computer RAD trig info in rads, not degrees READ get info from DATA lines 122 REM ignore these remarks RESTORE allows DATA lines to be re-read RETURN back from subroutine to main program RND random number between 0 and 1 RUN execute a program SAVE store data or program on disk SETCOLOR store color data SGN find sign of a number SIN sine SOUND control pitch, volume, tone SQR square root STATUS asks state of I/O device STEP size of skip in FOR/NEXT loop STICK position of stick game controller STRIG determines if stick trigger button is pressed STOP temporary program run halt STR$ changes number to character string THEN IF true, does what follows TO part of FOR/NEXT loop range TRAP on input error, jumps to a line USR machine-language subroutine VAL converts string to a number XIO I/O in graphics or disk work 123 Appendix B: Error Messages These are the messages your computer is trying to send you when it presents an error number. Naturally, it tells you the line number where the error is located. Number Message 2 you have used up all available memory 3 the number can’t have the value it has 4 you are only allowed 128 different variable names 5 your string is longer than the space you dimensioned 6 you are tryng to READ more DATA than you have available 7 a number is greater than 32767 8 you are trying to put string data in a number variable 9 you have not dimensioned an array or string properly 124 10 you simply have too many GOSUBs 11 you either have tried to divide by zero or else you want a result too large or too small for the computer to handle 12 you are using GOSUB or GOTO or THEN to jump to a nonexistent line number 13 you have a NEXT but there was no FOR 14 the statement simply is too long or too com¬ plex for BASIC to handle 15 again you have tried a NEXT or a RETURN without the necessary FOR or GOSUB 16 there is a RETURN without a GOSUB 17 don’t POKE there; try NEW to get out of this mess; if that doesn’t work, kill the power and turn it back on and re-enter the program without POKEs 18 you are trying to use an invalid string character 19 there’s not enough memory to complete the LOAD 20 you have a device number larger than 7 or equal to zero 21 you are trying to LOAD a no-LOAD file 128 you hit the BREAK key while the machine was doing something 129 the input/output control block already is open 130 you are calling for a nonexistent device 131 you have sent a read command to a write- only device, the printer 132 you can’t use that command for that device 133 you forgot to open the file or device 134 that is an illegal device number 135 you are trying to send a write command to a read-only device 136 you have read to the end of the file 137 you are trying to read a record longer than 256 characters 138 tape loading error 139 you are getting garbage at a serial port or else you have a bad disk drive 140 input framing error 125 141 your cursor is out of range for that mode 142 serial bus data frame overrun 143 serial bus data frame checksum error 144 you are trying to write on a write-protected disk 145 something’s wrong with what you just wrote 146 that function is not implemented 147 you don’t have enough memory available for the graphics mode you selected 160 that’s a drive number error 161 you have too many files OPENed 162 the disk is full 163 you’ve blown the whole bit 164 file numbers don’t match, the disk links are messed up 165 that’s a file name error 166 there’s an error in the POINT data length 167 that file is locked 168 that command is invalid 169 the directory is full 170 that file cannot be located anywhere 171 the POINT is invalid 126 101 Tips Worksheet Because of variances in program recorder’s tape counters, the start¬ ing number for each program on the 101 Programming Tips & Tricks companion cassette may vary with different program recorders. As you load each program into your ATARI Home Computer, you should note the actual starting number and write it down in the ACTUAL START column. PROGRAM NAME 1 Coin Toss. 2 Traditional Dice Roll. 3 See Two Dice. 4 See Four Dice." . . . 5 Secret Message. 6 Sound Off. 7 Ring the Bell I. 8 Ring the Bell II. 9 Mystery Clues. 10 Original Hi/Lo Game. 11 Code Groups. 12 60-Second Timer. 13 Find Highest/Lowest. 14 Sorting Scores. 15 -Keeping Game Scores. . . 16 Batting Average. 17 Computer Rating Service. . 18 Box Score. 19 Create a Quiz. .. 20 Killing Time.. 21 Word-Error Trapping. . v :. 22 Character Numbers. 23 One-Time Password. 24 Three-Tries Password. 25 Multiple Passwords. v .. 26 Name in a Box. °. . 27 Entering: Zero Stop. 28 Entering: Letter Stop. 29 Title Billboard. 30 Marching Numbers. 31 Wipeout! ; .. 32 Sentence Writer. 33 Categorizing. 34 Alphabet Soup. 35 Create a Table. . . .. 36 Question & Answer. . . .. 37 Gee Whiz I: Smart Adder. 38 Gee Whiz II: Three-Digit Mystery. 39 Gee Whiz III: Yes/No Decision Maker.... 40 Gee Whiz IV: First Alphabet Spotter. 41 Gee Whiz V: Second Alphabet Spotter. 42 Gee Whiz VI: Guess the Number. 43 Memory Tester. 44 Number Reverser. 45 Exam Score Sorter. 46 Number-Error Trapping. ACTUAL START / 127 ACTUAL PROGRAM NAME START 47 Standard Deviation. ■ 48 Percentages. ' _ 49 Logic Functions.. 50 Above & Below a Line.. 51 Factoring. j _ 52 Which Is Smallest?. . . .. 53 Which Is Largest?.. 54 Reciprocals.. 55 Dump the Integer.. 56 Averages. . 57 Mid-Range Number.. 58 Rounding Off.. 59 Two-Digit Round Off. ; _ 60 ^feeftWe-Decimal.. ■ _ 61 Every 10th Answer.. 62 Random Sampler.. 63 Random Numbers: Zero to Nine. : _ 64 Random Numbers: Distribution.. 65 Random Numbers: Averages.. 66 Random Numbers: Sorting High/Low.. 67 Money Grows.. 68 Shopper’s Friend. . .. 69 Car Payments.. 70 To Nearest 95 Cents... 71 To the Nearest Penny. . 72 Markup.. 73 Percentage Off.. 74 Dollars & Cents.. 75 Wages & Hours.. 76 Invoicing.•.. . 77 Unit Price. _ 78 Inventory Counter.. 79 Daily Code.. 80 Aztec Art... 81 Sine Wave.. 82 Hold That Pose.. 83 Okay, Now Wave.. 84 Moving Illusion.. 85 Super Moving Illusion.. 86 The Seamstress.. 87 Swimming Fish.. 88 Circling Dot.. 89 Box the Screen. . ; .. 90 Window Twinklers.. 91 Horn-In-Funnel Art.. 92 Blackboard. . 93 Snowfall... 94 Making Things Move. . ... 95 Draw a Box.. 96 Luminance Demonstrator.. 97 Draw a Line.:.. 98 Flashing Graphics Cursor.. 99 Boxed Title.. 100 Draw Bar Graphs.. 101 Background Cycler... 128 Here’s a giant collection of practical, useful, efficient programming techniques and operating shortcuts, for ATARI Home Computers, right out of a master programmers notebook. Loaded with hints, secrets, tips, tricks and easy-to-follow instructions, this book shows you how to handle routine programming chores on the ATARI Home Computer more quickly, do special effects, make your computer work for you—faster and more efficiently. Each of the 101 computer programming tips in this book features a complete ready-to-run program. Each will run immediately, as you find it in this book, or it easily can be included in a larger set of instructions to your computer. All 101 programs have been tested thoroughly on the ATARI Home Computers and are ready to load and run. The programs in this book are also available on a companion cassette in selected ATARI Paks. Learn insider’s how-to secrets for using the special, exciting BASIC words READ, DATA, RESTORE, INPUT, LEN, GOSUB, RETURN, VAL, ASC, CHR$, PRINT, DIM, FOR, NEXT, IF, THEN, DRAWTO, SET, COLOR, and many more. Sections in this book include a detailed Introduction; Fun and Games; Text on Text; Gee Whiz; Number Crunching; Money Matters; Colorful Graphics; and a handy Appendix. ‘ You will find special techniques for graphics; colorful program titles and billboards; coin toss; dice throw; secret message; bell ringer; mystery clues; code groups; 60-second timer; sorting; ordering; searching; averaging; passwords; sentence writer; creating tables; memory tester; exam sorter; rounding off; random numbers; shopper’s friend; interest on money; car payments; wages 7 hours; percentage off and mark up; invoicing; inventory counter; lists; two dozen exciting graphics programs; and many more. You’ll learn what to do, how to do it, when to make changes and when not to, all from this info-packed ATARI Home Computer programmer’s handbook of tips and tricks. ARCsoft Publishers Woodsboro, Maryland CO 61832 Rev. A