The/excitmg software ideabook, overflowing\with pro/techniques, hinis, secrets, shortcuts, witr I f\4 ATARI X^^X Computer Programming Tips & Tricks M^JX Computer Programming Tips & Tricks by Alan North ARCsoft Publishers WOODSBORO, MARYLAND FIRST EDITION FIRST PRINTING ) ) > 30 PRINT "TAILS" 40 PRINT SPRINT 50 PRINT "FOR MORE. i PRE 60 DIM K*( I ) ! INPUT K* 70 CLR sGOTO 10 CLEAR :i. THEN PRINT RETURN" 2 Traditional Dice Roll Here's a simple, brief way to roll and display results for two dice. Lines 100-110 get a random number between 1 and 6 and store it in A. Lines 200-210 get another random number from 1 to 6 and store it in B. Lines 300-310 print the contents of A and B along with a suitable message. 18 Program Listing 10 ] JIM K$. : 1 ) 20 i 3 RINT ' 1 \ II a REM SCREEN CLEAR 100 A --INT* ; 7* ( RND( 1 ) ) ) 110 IF A<] t THEN 100 200 B=INT< : 7* ( i RND < 1 ) ) ) 210 IF B<] . THI EN 200 300 PRINT "FI! RST DICE:" , A 3 1 PRINT "SE> COND DICE:" »B 400 FOR L= = 1 T< D 10: PRINT sNEXT L 410 PRINT " TO ROLL AGAIN , PRESS 420 INPUT K* 430 GOTO 20 RETURN' 3 See Two Dice Here's a quick way to add real dice to any fun pro- gram you are designing for your Atari. This program rolls two dice and lets you see the results, as with real dice. This is especially useful in those games where it is important to see the value of each. The subroutine in lines 100-140 generates the necessary pair of random numbers. Lines 60, 70 and 80 make the display you want. Note that lines 60 and 80 each have nine asterisks. Line 140 is RETURN and must be the last line in the pro- gram. After you type in and RUN the program, press any key on your Atari 's keyboard to roll the dice. Program Listing 10 PRINT "}":REM CLEAR SCREEN 20 DIM K*< 1 ) 30 PRINT "TO ROLL TWO DICE, PRESS RETURN' 40 INPUT K*: PRINT : PRINT 50 GOSUE 100 19 6GD PRINT "***#***#*" 70 PRINT "* " ;DL 1 " * " ?DRi 80 PR I NT " **•**#*#*# " ^0 PRINT "PRINT 5 GOTO 30 100 DL.»*INT<7*"SREM CLEAR SCREEN 20 DIN K*< 1 ) 30 PRINT "TO ROLL DICE, PRESS RETURN" 40 INPUT K*: PRINT :PRINT 50 FOR L»i TO 2 60 DQ=INT(7*(RND( 1) ) ) 70 IF D6K1 THEN 60 80 DR=INT<7*" SREM BUZZER 40 FOR L=J. TO 1 00 5 NEXT L 50 NEXT N 9 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 M"!REM CLEAR SCREEN 15 DIM A$ <6>, X*(6) 20 X*==" BUTLER" 30 PRINT "WHODUNIT ";: INPUT A* 40 IF X*=A$ THEN PRINT "PRINT "YES, YOU GUESSED IT" SPRINT :S0T0 20 50 PRINT SPRINT "CLUE: "," SERVANT" : PRINT :PRINT s 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(3 R=INT< 1000*(RND( 1 ) ) ) 200 PRINT " }" sREM BUZZER 210 PR I NT " SUE SS THE NUN BE R " i I N PUT B 220 T=T+i 230 PRINT : PRINT "THAT WAS TRY NO. " ; T 300 IF B>R THEN PRINT SPRINT "TOO HIGH GUESS AGAIN" : INPUT B'.GOTO 220 310 IF BHS THEN HS=SsHN*=N* 110 GOTO 40 120 PRINT SPRINT 130 PRINT LN*?" SCORED LOWEST AT ";LS 140 PRINT HN*?" SCORED HIGHEST AT "NHS 150 PRINT SPRINT : PRINT : PR I NT 160 PRINT "TO DO MORE., PRESS RETURN" 170 INPUT K$ 180 CLR (GOTO 10 27 14 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 want your Atari to compute final results. 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 INPUT N 10 PRINT " ! " ! REM CLEAR SCREEN 20 DIM K*< 1 ) 30 PRINT " TYPE IN A SCORE: II ii i 40 IF N=0 THEN 100 50 S-B+l 60 IF S=l THEN LI' 4=N!HN=N 70 IF NHM THEN HN=N 9(3 GOTO 30 100 PRINT 110 PRINT "LOW Nl JMBER IS "5! L..N 120 PRINT "HIGH NUMBER IS " ?Hr- 130 PRE- SPRINT ! PRINT 140 PRINT "FOR A DIFFERENT" 150 PRINT "SET OF r NUMBERS, " 160 PRINT "PRESS RETURN" 170 INPUT K$ 130 CLR !G OTO 10 Sample Run RUN RETURN TYPE IN A SCORE 22 RETURN 55 RETURN 28 77 RETURN 11 RETURN RETURN LOW NUMBER IS 11 HIGH NUMBER IS 77 15 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 Iine160 answer 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 ■ }":REM CLEAR SCREEN 20 DIM A*<7),E*<7> , C* < 7 ) , D* ( 7 ) 30 DIM E*<7),F*<7) , G* ( 7 ) , P* ( 7 ) 40 S=aNT(7*(RND< 1) ) ) 50 IF S<1 THEN 40 29 60 FOR L=l TO S 70 READ A* 80 NEXT L 90 RESTORE : PRINT "********************" 100 PRINT "WHO KILLED THE DUKE ?" 110 READ B*, C*,D*,E*,F*,6* 120 RESTORE 130 PRINT SPRINT "WAS IT THE..." 1 40 P R I NT E$ , C* , D$ , E$ , F* , 6$ 150 PRINT SPRINT " > ■ I REM BUZZER 160 PRINT "WHODUNIT "|« INPUT P$ 170 IF A*=P$ THEN R=R+1 : PRINT : PRINT "OK YOU ARE RIGHT" SPRINT "IT WAS THE "5 A*! GOTO 200 180 PRINT SPRINT "NO! NOT THE ■ 5 P* l W=WH- 1 SPRINT s GOTO 100 200 PRINT 210 PRINT "YOUR SCORE IS..." 220 PR I NT R : " R I GHT " , W ? " WRONG " 230 PRINT SPRINT sGOTO 40 300 DATA BUTLER , NANNY , GARDNER , BURGLAR , SON, WIFE 16 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 PRINT MM REM CLEAR SCREEN 80 PR I N T " N U M B E R R I G H T : " ; 810 INPUT R 820 PRINT "NUMBER TRIES: " i 830 INPUT T 900 PRINT R;" RIGHT" 9 1 P R I NT " I N " ; T 5 " T R I E S " 920 D=R/T : P= 1 00*D : B= I NT ( 1 0*P ) 930 PRINT "THAT'S " ; P ; " PERCEN" 940 PRINT "YOU ARE BATTING "?B 17 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 H >"sREM CLEAR SCREEN 700 PRINT "NUMBER RIGHT: "? 710 INPUT G 720 PRINT "NUMBER OF TRIES: "; 730 INPUT E 800 PRINT G?" RIGHT IN " ; E ; " TRIES" 810 H = I M T ( ( G / E ) * 1 ) 820 PRINT "YOU ARE BATTING " ; H 830 PRINT "YOU ARE " | 340 IF H<100 THEN GOTO 910 950 IF H<300 THEN GOTO 920 860 IF H<500 THEN GOTO 930 31 870 IF H<700 THEN GOTO 940 ■'00 THEN GOTO 950 " H A L L F F A M E " : G T 960 "THE PITS" ::GOTO 960 "POOR" 5QOTO 960 "AVERAGE" JGOTO 960 "TOP NOTCH" 5 GOTO 960 "DAMN NEAR PERFECT! " "YOUR BATTING AVERAGE IS "?H 880 IF H< 900 PRINT 910 PRINT- 920 PRINT 930 PRINT 940 PRINT 950 PRINT 960 PRINT 970 END 18 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 SC REE :n 20 DIM N*( 20 ) , S$ < S) 30 PRINT " PL A YER ? S NAME: 1! a 1 40 INPUT N* 50 PRINT " PL A YER' S SCORE: M « 1 60 INPUT £ 70 PRINT 80 S*=STR3 t(S) 90 LM=LEN < Nf ) +LEN ( S$ ) 100 LT=LN-* 14 110 FOR L* a T LT 120 PRINT " * " 5 130 NEXT L 140 PRINT 150 PRINT "# "iN»t"*B SCORE: ";S*;" *" 160 FOR L=l TO LT 170 PRINT "*" 5 1S0 NEXT L 190 PRINT SPRINT :60T0 30 32 Sample Run * EDWARD'S SCORE:: 1234 * 33 Text On Text 19 Create a Quiz One of the most fascinating uses for your Atari is in having it carry on a video conversation with your friends, relatives and neighbors. One useful way to pro- mote such conversation is through a quiz. An instruc tional, educational quiz, such as we have here. Quiz data— the computer's storehouse of know- ledge—is in lines 20 to 70. Be careful, when you type them into your Atari , to include the commas separating the two halfs of each data line. Spelling and spacing must be exact. Lines 90 and 100 obtain a random number in the range of 1 to 11. Line 110 selects the data line for a ques- tion. Lines 120 through 140 get the appropriate word FIRST, SECOND, THIRD, FOURTH, FIFTH or SIXTH from the selected data line. Lines 160 to 180 print the quiz question on the screen, while line 190 reads the DATA line to learn the correct answer. You provide your response when the computer asks for it at line 200. Lines 220-240 decide whether you are right or wrong. Of course, the quiz can be made much longer. In this example, it could be expanded to encompass all past U.S. presidents. Program Listing 10 PRINT " >":REM CLEAR SCREEN 15 DIM S$<9)„ C*(20) ,D$<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" 90 R= I NT ( 1 2* ( RND < 1 ) ) ) 100 IF R<1 THEN 90 110 IF INT(R/2)=R/2 THEN R=R+l 36 120 FOR L=i TO P 130 READ S$ 140 NEXT L 150 PRINT SPRINT 160 PRINT "WHO WAS THE" 170 PRINT S* 180 PRINT "PRESIDENT OF THE U.S." 190 READ C$ 200 INPUT D* 210 PRINT 220 IF D*=C* THEN PRINT "THAT'S CORRECT "- GOTO 240 230 PRINT "THAT'S WRONG" 240 PRINT "THE "IS*!" PRESIDENT WAS " 250 PRINT C* 260 RESTORE 270 PRINT SPRINT 2S0 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 ">"sREN SCREEN CLEAR 20 PRINT "GIVE ME A NUMBER " 3 s INPUT N 37 30 FOR L=l TO M 40 X=X+l_ 50 FOR T=l TO 100: NEXT T 60 PRINT "}" :REM SCREEN CLEAR 70 FOR T=l TO 100: NEXT T 80 PRINT " I AN THINKING" 90 NEXT L 100 PRINT ">":REM SCREEN CLEAR 110 PRINT "I HAVE THE ANSWER" : PR INT 12(3 PRINT "THE TOTAL OF ALL NUMBERS" 130 PRINT "FROM J. TO " ; N ; " IS " : X 200 PRINT : PR I NT SPRINT 210 CLR : GOTO 20 21 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) SPRINT " > " s REM CLEAR SCREEN 10 PRINT "WANT TO PLAY AGAIN " : : 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 !€0T0 10 100 PRINT "THANK YOU FOR THAT " ; A* 110 PRINT : PRINT I GOTO 10 200 PRINT "THANK YOU FOR THAT " *,A* 210 PRINT : PR I NT sSOTO 10 22 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 CLEAR 10 PRINT " >" :REM SCREEN 20 FOR N=0 TO 255 30 PRINT N,CHR*(N) 40 FOR T»l TO 400: NEXT 50 NEXT N 60 PRINT " }" :REM EUZZER 23 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 1(3 PRINT ">"*REM CLEAR SCREEN 15 DIM A$(8) 20 PRINT "WHAT IS THE PASSWORD "?: INPUT A* 30 IF A*- "ELEPHANT" THEN 1.00 40 END 10S PRINT "YOU GOT IT RIGHT" 110 PRINT "NOW THE PROGRAM WOULD RUN" 24 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 ">"*REN CLEAR SCREEN 15 DIM A* (8) 20 PRINT "WHAT IS THE PASSWORD " s: INPUT A* 30 IF A$=" 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 25 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=l TO 3 30 PRINT "YOUR ACCOUNT NUMBER: ", I INPUT 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 "HOW THE PROGRAM WOULD RUN" 120 END 300 IF UA^ .1.23 45 THEN PW*^" ZEBRA" 310 IF UA«23456 THEN PW*-" GOOSE" 41 320 IF UA=3456 7 THEM PW*= B TROUT ,! 330 IF UA-4567 8 THEN PW$=" SNAKE" 340 RETURN 26 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 lines 80, 110 and 130. Program Listing 10 PRINT "}""REM SCREEN CLEAR 20 DIM N$(26) , K$( 1 ) 30 PRINT "PRINT "WHAT IS YOUR NAME" 40 INPUT N* 50 LN=LEN ( N$ ) : LT=LN+4 60 PRINT SPRINT " )• " : REM CLEAR SCREEN 70 FOR L=l TO LT 80 PRINT "*" 5 90 NEXT L 100 PRINT 110 PRINT "* " ?N*S M #" 120 FOR L---1 TO LT 130 PRINT "*" 5 140 NEXT L 150 FOR L~l TO 10 160 PRINT 170 NEXT L 180 CLR sGOTO 20 42 27 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 1 10 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 "}"nREM SCREEN CLEAR 20 B=0 100 PRINT "GIVE ME A NUMBER" : INPUT A 110 IF A=0 THEN 200 120 E=B+A 130 PRINT JSOTO 100 200 PRINT ! PR I NT : PRINT 210 PRINT "THE TOTAL OF THOSE NUMBERS IS "5 B 300 PRINT ! PRINT : PRINT : PRINT 310 GOTO 20 28 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 ">"!REM CLEAR SCREEN 20 CLR 30 DIM A$(20) 100 PRINT "GIVE ME A NUMBER :", l INPUT A* 110 IF A$="X" THEN 200 120 E=VAL(A$) 130 OC+B 140 GOTO 100 200 PRINT SPRINT : PRINT 210 PRINT "THE TOTAL OF THOSE NUMBERS IS " i C 30(3 PRINT SPRINT : PRINT : PRINT 310 GOTO 20 29 Title Billboard This program opens a light window against a dark background. It can be placed anywhere on the graphics screen. Move the window by changing the range of values for X and for Y in lines 1030 and 1040. Move the lettering around by changing the PLOT and DRAWTO locations specified in lines 1090 to 1290. Line 1300 is a freeze-frame, used to hold the picture. It is an endless loop which will remain forever at line 1300 until you press the BREAK key. Remember how to make this freeze-frame. You might like to use it in some pro- gram in the future. Program Listing 1000 GRAPHICS 10 1020 COLOR 1 1030 FOR X»iS TO 75 1040 FOR Y=10 TO 45 1050 PLOT X,Y 1060 NEXT Y 1070 NEXT X 44 1080 COLOR 8 1090 PLOT 20,20 1100 DRAWTO 30,20 11 10 DRAWTO 25,20 1120 DRAWTO 25,30 1 1 30 PLOT 35 , 20 1140 DRAWTO 35,30 1150 PLOT 40,20 1160 DRAWTO 50,20 1170 DRAWTO 45,20 1180 DRAWTO 45,30 1190 PLOT 55,20 1200 DRAWTO 55,30 1210 DRAWTO 60,30 1220 PLOT 65,20 1230 DRAWTO 70,20 1240 DRAWTO 65,20 1250 DRAWTO 65,25 1260 DRAWTO 70,25 1270 DRAWTO 65,25 1280 DRAWTO 65,30 1290 DRAWTO 70,30 1300 GOTO 1300 30 Marching Numbers This little program does a big job! It creates the unusual display of numbers from one to nine marching across the screen. Try it; you'll like it. Program Listing SCREEN 10 PRINT " !" sREM CLEAR S 20 X=0 30 X = X-+-1 40 IP X>9 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. Watch out when testing. A wrong password can cause a lot of retyp- ing. Program Listing 10 PRINT ") M sREM CLEAR SCREEN 15 DIM P$<20> 20 PRINT "WHAT I S3 THE PASSWORDS "; s INPUT P$ 30 IF P*=" TRACEY" THEN 50 40 NEW 50 PRINT "CORRECT" 60 PRINT P*?" IS THE PASSWORD" 32 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 Dili N$( 15) n V*( 15) , S*( 15) , K*< 1 ) 20 PRINT "A PLURAL. NOUN : " , : INPUT N* 30 PRINT "A VERBS", ,« INPUT V* 40 PRINT "A SINGULAR NOUN : " , : INPUT S* 50 PRINT -PRINT 60 PR I NT " THE " ; N* |" " ; V* I " " ; B* ; " . " 70 FOR L=l TO 10s PRINT sNEXT L 80 PRINT "PRESS RETURN" 90 INPUT K* 1O0 CLR :GOTO 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 33 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 " }" SREM CLEAR S GREEN 20 DIM G*< 10>,K*< 1 ) 30 PRINT "ENTER A GROUP • OF SCORES" 40 PRINT "FROM TO 100, ONE AT A TI 50 PRINT "ENTER X AFTER ! ....AST SCORE" 60 PRINT :PRINT "SCORE; " 5 : INPUT G* 70 IF G$="X" THEN 200 80 6=VAL ( G* ) 90 n=N+1 100 IF G<60 THEN F=F + 1:G- 0TO 150 110 IF G<70 THEM D=D+15Q< DTO 150 120 IF GH THEN H=G 180 S=3+G 190 GOTO 60 200 P=S/N:M=L+< ( H-L )/2) 210 PRINT "}" sREM SCREEN CLEAR 220 PRINT "THERE WERE "51 M?" SCORES" 230 PRINT "RANGING FROM ■ 5L ? " TO " ; H 48 PRINT " M I D -RANGE ! 3 CO RE: g 11 1 M AVERAGE SC ORE: :",P PRINT " TOT ALS FOR EA CH LE TTER 240 PRINT 250 PRINT 263 PRINT GRADE: " 270 PRINT SPRINT " A : " , A 230 PRINT "Bs " ,B 290 PRINT "Cs " , C 300 PRINT "D!" ,D 310 PRINT "F: " , F 400 PRINT : PRINT s PRINT 410 PRINT "FOR MORE, PRESS RETURN" 420 INPUT K$ 430 CLR 5 GOTO 10 34 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 SCREEN 10 PRINT " ) " sREM CLEAR 20 DIM X$(l) 30 P= I NT ( 9 1 # < RND ( 1 ) ) ) 40 IF P<65 THEN 30 50 X*=CHR*50 THEM A^A+UGOTO 20 40 GOSUE 900 50 IF X>50 THEN B=B+l:GOTO 20 60 GOSUE 900 70 IF X>5© THEN C=C+1 «GOTO 20 100 PRINT A,B»CUF T=*19 THEN 200 110 A=0!B™0:C=0sT=T+lsSOTO 20 200 GOTO 200 900 X= I NT < 1 00* ( RMD ( 1 ) ) ) 910 RETURN 50 36 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 "V'sREM CLEAR SCREEN 15 DIM B$(9), C$(2),D*(2) 20 DAT A J ANU A R Y , 3 1 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=l TO R 1.80 READ S* 190 NEXT L 200 PRINT "MONTH IS " ; S* 210 READ C* 220 PRINT "HOW MANY DAYS M 5 i INPUT D* 230 IF D*=C* THEN PRINT : PRINT "CORRECT" :GOTO 300 51 240 PRINT SPRINT "WRONG" 30(3 PRINT "NUMBER OF DAYS IS 31@ RESTORE 320 FOR L=l TO 5 "PRINT :NEXT 330 CLR KGOTO 15 L 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 Atari 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 Atari 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 Atari do it in a split second. Your neighbor's reaction is bound to be, "Gee whiz!" Program Listing INPUT N 10 PRINT " ) " ! REM CLEAR SCREEN 20 PRINT "GIVE ME A NUMBERS 30 IF N<1 THEN 20 40 FOR L= = 1 TO N!X=X+L:NEXT L 50 PRINT " }" 5 REM BUZZER 60 PRINT "THE TOTAL OF 1 TO " 70 PRINT SPRINT sCLR SGOTO 20 ;N? 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 " } " s REM SCREEN CLEAR 20 PRINT "SELECT A THREE-DIGIT NUMBER" 30 PRINT "ALL THREE DIGITS THE SAME" 40 PRINT 50 PRINT "ADD THE THREE DIGITS TOGETHER' 60 PRINT 70 PRINT "WHAT IS THE SUM" 80 PRINT "OF THE THREE DIGITS ■ 1 90 INPUT N 100 IF N<3 OR N>27 THEN 90 110 6$=37*N 120 PRINT :PRINT 130 PRINT "}":REM BUZZER 140 PRINT "YOUR NUMBER IS " ; Q 150 PRINT SPRINT SGOTO 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 "}"sREM SCREEN CLEAR 20 X=100*< RNDC 1 ) > 30 IF X>49 THEN PRINT "YES" ! SOTO 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 Atari is a genius! Program Listing 10 PRINT " }'* : REM 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 60 X=N+64 70 PRINT SPRINT "PRINT 80 PRINT "LETTER NUMBER H :N§" IS "?CHR*(X> 90 PRINT : PRINT SPRINT 100 GOTO 20 41 Gee Whiz V: Second Alphabet Spotter This is a variation on the previous program. 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. Program Listing 10 PRINT "}"sREM CLEAR SCREEN 20 DIM A$ < 1 ) 57 30 DA'T'A A , E, C, D, E * F , G, H, I « J, Ki !.... , M 40 DATA N i i P , Q i P , S , T , U , V , W , X , Y , Z 50 PRINT "GIVE HE! THE NUMBER OF" 60 PRINT "A LETTER FROM THE ALPHABET" 70 PRINT "FROM 1 TO 26" 80 INPUT N 90 FOR L=l TO N 100 READ A* 110 NEXT L 120 PRINT SPRINT 130 PRINT " }" : REM BUZZER 140 PRINT "LETTER NUMBER "»Nl" IS "5A$ 150 RESTORE 160 PRINT :PRINT 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 "}":REM CLEAR SCREEN 20 DIM 0$( 1) 30 Q$=" *" 40 GOTO 110 50 N=INT< 101*(RMD( 1 ) ) ) 60 PRINT "GUESS THE NUMBER" , : INPUT G 70 IF G>N THEN PRINT "TOO HIGH" s GOTO 60 80 IF G " , N 60 IF W=3 THEN PRINT " FORGET IT !" SG0TO 140 70 FOR T=l TO 500 ".NEXT T 80 PRINT " }""REM CLEAR SCREEN 90 PRINT "WHAT WAS IT", * INPUT S 10© IF SON THEN PRINT " #**YOU ARE WRONG !" s W« W + 1 « GOTO 60 110 PRINT "YOU ARE RIGHT ! " i R=R+i s Z=Z*10 120 PRINT R?" RIGHT SO FAR" 130 PRINT :GOTO 30 14© PRINT : PR I NT "YOU HAD " ; R ; " RIGHT" 150 PRINT SPRINT "LET'S START OVER" 160 PRINT "PRESS RETURN" 170 DIM K*< 1 ) 180 INPUT K$ 190 CLR 5 GOTO 1.0 63 44 Number Reverser Give your Atari any 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 IS PRINT " }"SREM SCREEN CLEAR 20 PRINT "ENTER A THREE-DIGIT NUMBERS " 30 INPUT N 40 IF N<100 OR N>999 THEN 20 50 A- I NT £N/ 100) 60 E= I NT ( 1 0* ( < N/ 1 00 ) A ) ) 70 C= I NT ( 10* ( ( N/ 1 ) ( INT ( N/ 10)))) 80 PRINT C?B,A 90 PRINT ."PRINT 100 CLR s GOTO 20 45 Exam Score Sorter A quick way to sort and count a book full of letter grades, this program permits one-key entry of a mixed series of data. We use the familiar letter grades A, B, C, D, and F. You may substitute any other set of five characters you wish in the IF statements in lines 80 to 120. The letter X is used to conclude the series and lead the computer to display final results. You press the appropriate keyandthe computerknows immediately what grade you have indicated. Key in as many grades as you like in any mixed order. When you have completed entering all grades, type in the letter X. The computer will report the total of A's, B's, C's, D's, and F's. We use exam-score sorting as our example here but this same program would be good for data collection in the field 64 in many professions. And you can stretch out the possible categories to 25 or more. To make the program run again, press the RETURN key on the computer's keyboard. Program Listing 10 PRINT "}":REM SCREEN CLEAR 20 DIM G*( 1 ) ,K*< 1 ) 30 PRINT "ENTER LETTER GRADES:" 40 INPUT G* 50 IF G*="X" THEN 140 80 IF G$="A" THEN A=A+1 : GOTO 40 90 IF G$«"B" THEN B=B+lsGGTO 40 100 IF 6*="C" THEN OC+lsGOTO 40 1 1 IF G*="D" THEN D=D+HGOTO 40 120 IF G$^"F" THEN F=F+l«GOTO 40 130 GOTO 40 140 PRINT "V'sREM SCREEN CLEAR 150 PRINT "A::", A 160 PRINT "B!"«l 170 PRINT "C"",C 180 PRINT "D:",D 190 PRINT "F:",F 200 PRINT SPRINT SPRINT 210 PRINT "FOR MORE, PRESS RETURh 220 INPUT K$ 230 CLR 5GOTO 10 Sample Run ENTER LETTER GRADES A C F D B A B C C C D 65 A: 2 B: 2 C: 4 D: 2 F: 2 46 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 "}":REI1 CLEAR SCREEN 10 PRINT "GIVE ME A NUMBER ";: INPUT A 20 IF A<10 THEN PRINT "TOO LOW" J SOTO 10 30 IF AM 00 THEN PRINT " TOO HIGH" :GOTO 10 40 PRINT A 66 47 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 stan- dard deviation computations. Try a series of data points such as 3, 5, 3, 7, and 4. They should result in DATA P< ME! AN: VARIAN' )INT TOTAL 2399909 49666253 Program Listing 10 20 30 40 50 60 70 80 90 10 PRINT ")""REM SCREEN CLEAR PR I NT " DATA PQ I NT s " i i I NPUT IF >;=999999999 THEN 60 T=T-f-X!S=S+X A 2s| GOTO 20 A=T/N!V=S/N-A A : =N+l ;D=SQR(V) PRINT PRINT PRINT a PRINT 110 PRINT 120 PRINT 130 CLR Si i PR I NT DATA POINTS TOTAL MEAN: " , , A "VARIANCES " ,V "STD DEVIATION" " , SPRINT SOTO 20 ,T 48 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:; " 5 : INPUT P 30 D=0.01*P 40 PRINT "DECIMAL: " ,D 50 PRINT s GOTO 20 49 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 B }"!REM CLEAR SCREEN 20 £=10 30 C=18*B 4(3 IF B THEN PRINT C In the second program here, the Atari only displays the results of the tests in lines 40 and 50 if the results 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 " >":REM SCREEN CL 20 B- ( 6+8) > (3*4 ) 30 C- ( 5+2 ) > (9+2) 40 IF E THEN PRINT "B OKAY 50 IF C THEN PRINT "C OKAY 50 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 REM SCREEN CLEAR INPUT 10 PRINT ,! ) " s REM SCREEN CLEAR 20 PRINT " GIVE ME A NUMBER: " :; 30 IF Z=0 THEN 80 40 IF Z<1 OR Z>100 m 20 50 N=W+1 60 IF Z<51 THEN B =B+1 70 SOTO 20 ! 80 A=N---B 90 PRINT ! PRINT 100 PRINT "NUMBER S TOTAL ! " , N 110 PRINT " 1 TO 5 0" , ,E 120 PRINT "51 TO 1 00 8 " , A 13G ) PRINT : PRINT :PRINT sPRIN 1412 ) CLR "Q iOTO 20 51 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< 1700) 25 FOR L=0 TO 999 l Q ( L ) =0 : NEXT L 30 PRINT "NUMBER: " , : INPUT N 40 FOR L=2 TO N/2 50 M=N/L 60 IF M=INT(M) THEN 6$1. THEN PRINT Q(L) «GOTO 120 110 Z=Z+1 120 NEXT L 130 IF N=l THEN PRINT ■ NONE " s GOTO 150 140 IF 2= I NT (N/2) THEN PRINT "NONE" 150 PRINT :PRINT sGOTO 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 ">"IREM SCREEN CLEAR 20 PRINT "GIVE ME A NUMBER I", I INPUT Z 30 IF Z=0 THEN S0 40 N=N+1 50 IF N=l THEN D=Z 60 IF Z n *REM CLEAR SCREEN 20 PRINT "GIVE HE A NUMBER" ,'.' INPUT Z 30 IF Z=0 THEN 60 40 IF Z>D THEN D-Z 50 GOTO 20 60 PRINT SPRINT 70 PRINT "THE LARGEST NUMBER IS "?D 80 PRINT SPRINT : PRINT s PRINT 90 CLR sGOTO 20 54 Reciprocals Key in any number. The computer will display its reciprocal. The actual conversion is done here at line 30. Program Listing 1.0 PRINT "}"sREM SCREEN CLEAR 15 PRINT "NUMBER TO BE CONVERTED" 20 PRINT "TO ITS RECIPROCAL.: ■ » 25 INPUT M 30 R=l/N 35 PRINT ".PRINT 40 PRINT "RECIPROCAL. OF " ; N ; " IS ■ | R 45 PRINT SPRINT 50 CLR :GOT0 15 72 55 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" 30 PRINT "OF " !N5 " IS " ; X 90 PRINT : PRINT : PRINT ! PRINT 100 CLR SGOTO 20 56 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 " }" J REM CLEAR SCREEN "GIVE ME A NUMBER" , : INPUT Z THEN 70 10 PRINT 20 PRINT 30 IF Z=0 40 N=N+1 73 50 T«T+Z 60 GOTO 20 70 A=T/N 100 PRINT SPRINT 110 PRINT "THE AVE ;rage IS " 5 A 120 PRINT SPRINT ! PRINT SPRINT 130 CLR :<3> OTO 20 57 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 " } " : REM S CREEN CLEAR 20 PRINT *' GIVE ME A NUMBER" , s INPUT Z 30 IF Z=0 THEN 90 40 H-N+l 50 IF N=l THEN H==Z sL=Z 60 IF ZH THEN H=Z 80 GOTO 2INT(N> THEN 30 60 R=N 70 GOTO 130 80 D-N-INT(N) 90 IF D>0.5 THEN 120 10(3 R=INT(N) 11(3 GOTO 130 120 R=INT(N>+1 130 PRINT "}"SREM BUZZER 140 PRINT NS" ROUNDS OFF TO " ; R 15© PRINT ! PR I NT : PRINT 160 CLR sGOTO 20 The second set of program lines rounds off on the "less than five rounds down" theory. Program Listing 10 PRINT "}"«REM SCREEN CLEAR 20 PRINT "GIVE ME A NUMBER" 30 PRINT "TO BE ROUNDED OFF" 40 INPUT N 50 IF N>INT(N) THEN 80 60 R=N 70 GOTO 130 75 30 D=N-IMT(N) 9(3 IF D<0.5 THEN 120 100 R=INT 130 PRINT " }" 5 REM BUZZER 140 PRINT NS" ROUNDS OFF TO 150 PRINT SPRINT : PRINT 160 CLR ' GOTO 20 59 Two-Digit Round Off It is possible to round off to the nearest hundredths place. That is, to two digits after the decimal point. Here's how: Program Listing 10 PRINT "}"sREM SCREEN CLEAR 20 PRINT "GIVE ME A NUMBER TO" 30 PRINT "MORE THAN 2 DECIMAL PLACES? " 40 INPUT N 50 R= I NT ( 1 00*N+0 . 5 ) / 1 00 60 PRINT 70 PRINT IMS'* ROUNDS OFF TO " ; R 80 PRINT "OR" 90 PRINT "* M ?N5" BECOMES *" ?R 100 PRINT SPRINT SPRINT I PRINT 110 CLR SGOTO 20 60 Percent to Decimal Checking, interest, sales tax, and other financial pro- grams are more "user friendly" if you don't have to make manual conversions in your head. For example, if you know your savings account earns 8 percent interest, and 76 you need to multiply by the decimal value for 8 percent (which is 0.08), it is easier to be able to enter 8 and let the Atari figure out the decimal value. Here's another way to change percentages to deci- mals inside a program to simplify entry by permitting percents to be entered as simple numbers. For some examples, try entering a price of 2.50 and a sales tax percentage of 6. Your Atari will find the bill totals $2.65. Or try $7.80 and 5 percent tax. The bill will be $8.19. Try $123.75 at 8 percent tax. The bill will total $133.65. Program Listing 10 PRINT " !•" sREh t CLEAR SCREEN 20 PRINT "PRICE *", , S INPUT P 30 PRINT "SALES TAX "/.", : INPUT 40 T=*0„01*R 50 S=T*P:B=P-i-S 60 PRINT "SALES TAX" , "*" 5 3 70 PRINT "TOTAL BILL", "*" IB 80 PRINT : PRINT SPRINT SPRINT 90 CLR :GO'TO 20 61 Every 10th Answer This program generates a random number in the range of zero to 999. However, it has a difference. It only shows you every tenth number it generates. Line 20 generates the numbers. Line 40 selects the tenth number from each set. Program Listing 10 PRINT " >" :REM CLEAR SCREEN 20 T=INT( 1.000*49 THEN N=N+1 60 NEXT L 70 PRINT Y?" YES" 80 PRINT N?" NO" 9© PRINT SPRINT : PRINT 100 CLR ! 30 FOR L=l TO 200: NEXT L 40 GOTO 20 64 Random Numbers: Distribution Ever wonder how "random" are the numbers generated by the random-number generator in your Atari when you use the RND instruction? Try this pro- gram. 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 Atari prints a neat chart, on the video display, of results. See our sample run. Program Listing 10 PRINT ">":REM SCREEN CLEAR 79 20 1 r OR L»l TO 100 30 ! M=INT( 10* THEN 5=5+1 110 IF N=7 ' THEN H»H+1 120 IF N=E ! THEN 1*1 + 1 130 IF N-S > THEN J=J+1 140 PRINT "COUNTING" 150 NEXT L 160 PRINT " } " s REM CLEAR 170 PRINT " )" !REH BUZZER 200 PRINT "0" , A 210 PRINT " 1 " , B 220 PRINT II "i » P* 230 PRINT "3" , D 240 PRINT " 4 " , E 250 PRINT " 5 " , F 260 PRINT "6" ,G 27(3 PRINT " 7 " ., H 280 PRINT "8" , I 290 PRINT "9" , J 30(3 END Sample Run RUN RETURN COUNTING 8 ] 10 2 14 3 16 k 6 5 7 6 7 7 15 SCREEN 80 8 h 9 13 RUN RETURN COUNTING 6 1 12 2 11 3 13 k 7 5 12 6 9 7 10 8 8 9 12 65 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=INT< 10*" 8 REM SCREEN CLEAR 20 FOR L=0 TO 99 30 N= I NT ( 1 000* ( RND ( 1 ) ) ) 40 IF L=0 THEN LN=NsHN=N 50 IF NHN THEN HN=N 70 PRINT " SORTING" 80 NEXT L 90 PRINT C HR*<253) :REM BUZ ZER 100 PRINT " >" 5 REM CLEAR SC REEN 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 67 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 PRINT " }"*.REM CLEAR SCREEN 2© PRINT "PRINCIPAL. *",,« INPUT P 30 PRINT "ANNUAL INTEREST RATE "/.", S INPUT R 40 PRINT "NUMBER MONTHS" , ,: INPUT M 50 FOR Q»l TO M 60 I=»Y*<20),K*<1) 30 PRINT " SHOPPER'S FRIEND" 40 PRINT "FIRST BRAND »", s INPUT X* 50 PRINT "QUANTITY: ", : INPUT M 60 PRINT " PRICE s " , , s INPUT N 70 PRINT "SECOND BRAND! ",: INPUT Y$ 80 PRINT "QUANTITY:" ,! INPUT S 90 PR I NT "PRICE:",, I I NPUT R 100 IF N/M=R/Q THEN 500 110 IF N/TKR/Q THEN 300 200 PRINT SPRINT Y*5" IS BEST BUY" 210 GOTO 400 300 PRINT ! PR I NT X*J" IS BEST BUY" 400 PR I NT ! PR I NT X* 5 " UN IT:","*"? N/N 410 P R I NT Y* i " UN I T :","*"? R / 420 FOR L=l TO 8: PRINT SNEXT L 430 PRINT "TO DO ANOTHER, PRESS RETURN" 440 INPUT K'$ 87 450 CLR s GOTO 10 500 PRINT SPRINT X*i" = " ?Y$ 510 GOTO 4©0 69 Car Payments Shopping for a new car? Use your Atari computer to compute quickly the potential monthly car payment on various models. Imagine you want an $8000 car and are prepared to put up $1000 against the purchase. You want to arrange to finance the car for 36 months. You know the current annual interest rate on car loans is 15 percent. Key in those few numbers and the computer instantly tells you the car payment will be $242.66 per month. Program Listing 10 PRINT " } " s REN CLEAR SCREEN 20 DIM K$ ( 1 ) 30 FOR L= 1 TO 38s PRINT "*" : sNEX T L 40 PRINT " * 1 TO 38s AUTOMOBILE PAYMENT 50 FOR L~ PRINT »#" ; sNEX T L 60 PRINT "PURCHAE IE PRICE *8 11 u » 1 " INPUT T 70 PRINT "DOWN Pffi tYMENT * s " i , s INPUT R 80 PRINT "NUMBER OF MONTHS". ■ii" INPUT N 90 PRINT " ANNUAL INTEREST % u II " 11 s INPUT I 100 I=<0. 1 * I ) / 1 2 110 P= ( T- R > * I / < i - •1/C 1+1 ) A M) 120 PF*=INT ( 1 00*P+0 „ 5 ) / 1 00 130 PRINT s PRINT "PAYMENTS" , "$" 5PP 140 FOR L -1 TO 3E is PRINT "*" J s NE XT L 150 PRINT SPRINT 160 PRINT "FOR MC ■RE, PRESS RETURN" 170 INPUT K* 180 CLR sGOTO 10 88 70 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 IS PRINT ">""REM CLEAR SCREEN 20 PRINT "MANUFACTURING COST" *" : INPUT 30 PRINT "PRICING MULTIPLIER^ " ! INPUT M 40 P=INT<€*M)+0.95 50 PRINT 6 P R I N T "RET A I L P R I C E = $ " ; P 70 PRINT SPRINT 80 CLR :GOTO 20 Sample Run MFG COST = $ 1.12 RETURN PRICING MULTIPLIER = 10 RETURN RETAIL PRICE = $11 .95 RETURN 71 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 " }" 5 REM CLEAR SCREEN 20 PRINT "ENTER A NUMBER TO" 30 PRINT "MORE THAN TWO DECIMAL PLACES" 40 PRINT SPRINT "ORIGINAL AMOUNT - "s 50 INPUT N 60 R=INT< 100*N+0„5)/i00 70 PRINT SPRINT "TO THE NEAREST PENNY," B0 PRINT " $ " ? N 5 " I S * " 1 R 90 PRINT SPRINT 100 CLR s iQOTO 40 72 Mark Up Mr. Storekeeper, here's just what you have needed to compute mark ups. This program causes your APPLE to find the retail price for which your percentage off would give the wholesale cost. For instance, if you got 40 percent off on an item and paid $60, how much was it priced at, at retail? The answer is $100. To put that another way, if retail price or sug- gested retail price is $100 and you got 40 percent off at wholesale, what is the wholesale price? The answer is $60. Try $40 wholesale which is 60 percent off. The answer is $100 retail. Or try $10 wholesale at 90 percent off. Retail would be $100. Or $75 wholesale at 25 percent off gives $100 retail. Here's a toughie! Try $19.95 wholesale cost. Mark-up percentage is 40. The correct retail answer is $33.25. 90 Program Listing 10 PRINT ">":REM CLEAR SCREEN 20 PRINT "WHOLESALE COST *" : INPUT W 30 PRINT "MARK-UP PERCENTAGE X" s INPUT 40 D=.t 0„ 01*PsR=W/D 50 PR I NT " RETA I L PR I CE - $" % R 60 PRINT SPRINT 70 CLP sGOTO 20 73 Percentage Off From earlier tips in this book, you know how to make your Atari 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 a" : INPUT P 40 PRINT " ) " sREM CLEAR SCREEN 50 D=l-0. 01*P 60 PRINT "TO COMPUTE WITH " ; P ; " 7. OFF" 70 PRINT "THE DECIMAL WILL BE " ?D 80 PRINT 90 PRINT P ',""/. OFF $" ?L 10(3 PRINT "RESULTS IN A COST OF *" ;D*L 110 PRINT ' SPRINT 120 CLR : GOTO 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 " } " ! REM SCREEN CLEAR "QUANTITY:" , s INPUT P "TOTAL COST *" , : INPUT C THEN T-100*Ti6OTO SB "EACH COST $" IT s PRINT SCLR :GOTO 20 "EACH COST ";TS" CENTS" :PRINT :CLR SSOTO 20 10 PRINT 20 PRINT 30 PRINT 40 T=C/P 50 IF T<1 60 PRINT 70 PRINT 60 PRINT 90 PRINT 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 "}"SREM 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 WAGES »","♦" J W 7© END ! 00 W= ( 40*P ) -i- ( OT*P* 1 „ 5 ) 110 GOTO 60 Sample Run RUN RETURN HOURLY PAY RATE = $ 5.75 RETURN NUMBER HOURS WORKED = 61 RETURN GROSS WAGES = $411,125 76 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 "J": REM SCREEN CLEAR 20 PRINT "QUANTITY SOLD" , : INPUT Q 30 PRINT "UNIT PRICE ■ *" , : INPUT P 40 PRINT "SALESTAX RATE PERCENT**" 50 PRINT "SHIPPING CHARGES - *" , i INPUT H 60 3=0 . 01 *S : OQ*P s T=C*S : F=C+T+H 70 CO I NT ( 1 00*C+0 „ 5 ) / 1 00 80 TT= I NT ( 1 00* T+0 . 5 ) / 1 00 90 FF= I NT ( 1 00*F+0 . 5 ) / 1 00 100 PRINT ">" :REM CLEAR SCREEN 93 110 PRINT "TOTAL PRICE - $"", CC 120 PRINT "SALES TAX - *" JTT 130 PRINT "SHIPPING CHARGES ■ *" ?H 140 PRINT 150 PRINT "INVOICE TOTAL = $";PF 200 END Sample Run RUM RETURN QUANTITY SOLD 178 RETURN UNIT PRICE = $ 53.98 RETURN SALES TAX RATE PERCENT = 6 RETURN SHIPPING CHARGES = $ 100 RETURN TOTAL PRICE = $996^.^^ SALES TAX = $597.87 SHIPPING CHARGES = $100 INVOICE TOTAL = $10662.31 77 Unit Price Suppose you find 895 green Widgets and buy them for $695. How much did each green Widget cost? Rounded off, $7.77. 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 " \ II n REM SCREEN CLEAR 20 DIM N*< 20 ) , K$ ( 1 ) 30 PRINT " ITEM NAME IS " : INPUT N$ 40 PRINT " QUA NT I TV OF ITEMS ■ ! " : INPUT Q 50 PRINT " TOT AL PRICE PAID FOR ITEMS $" 60 INPUT P 70 U=P/Q 80 UU=IIMT< 100*U+0„5>/100 90 PRINT " REM BUZZER 100 PRINT N$; " UNIT PRICE = *" ! UU 110 PRINT :PRINT SPRINT 120 PRINT " TO DO MORE, PRESS RETURN" 130 INPUT K* 140 CLR !G OTO 10 Sample Run RUN RETURN ITEM NAME IS WIDGETS RETURN QUANTITY OE ITEMS = 999 RETURN TOTAL PRICE PAID EOR ITEMS = $ 14653 RETURN BEEP WIDGETS UNIT PRICE = $14.67 78 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 10. 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 discoverthatviathetest in Iine40and shipthe whole operation back to line 20 where it asks you again fora valid number. If, at line 40, it finds a valid item code number from one to ten it will allow the execution to goon 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 the lines 201 through 210end with ajumpto line 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 ">"nREM SCREEN CLEAR 20 PRINT "ITEM CODE: % s INPUT C 30 IF (>0 THEN 70 96 40 IF O10 THEN 20 50 1 °RINT "QUANTITY 60 1 SOTO C+200 70 ! SRI NT H )" : REM C 80 ( 5 OS UP 300 100 PRINT :PRINT " 1 1 DIM K*< 1 ) 120 INPUT K$ 130 CLR ' GOTO 10 201 J=J-M3 ; GOTO 20 202 K—K+Q " GOTO 20 203 L-L+Q ! GOTO 20 204 M=M+Q;GOTO 20 205 N=N+Q ! GOTO 20 206 R--R+0 "GOTO 20 207 S=S+&5GOTO 20 209 T=T+QsGOTO 20 209 y=y+0 : GOTO 20 210 y=y+$ s GOTO 20 220 END 300 PRINT "i:" i J 310 PRINT "2S" ,K 320 PRINT "3:" ,L 330 PRINT "4:" iM 340 PRINT "5:" »N 350 PRINT "A:" • R 360 PRINT "7:" Q 370 PRINT "8:" ,T 380 PRINT "?s" ,U 390 PRINT "10! " , V 400 RETURN 79 " " , : INPUT +10 60 PLOT X , Y 70 NEXT X 80 GOTO 80 82 Hold That Pose The illusion of motion is important in computer graphics. But, to make a character move, you have to draw it first! Here we have created a friendly little stick man. Lines 100 to 140 create the head. Lines 150 and 160, the eyes. Line 170, the nose. Lines 180 and 190, the mouth. Lines 200 to 280 create the body, legs and arms. But, having created him on the graphics screen, how can we keep him there? By using a freeze frame as we have done here in line 300. Line 300 is an endless loop, holding action at line 300 forever, until you press the break key. Run this program first. Then, go on to Tip Number 83. Program Listing 10 GRAPHICS 9 100 PLOT 35,50 110 DRAWTO 45 .,50 120 DRAWTO 45,70 130 DRAWTO 35,70 140 DRAWTO 35,50 150 PLOT 37,55 160 PLOT 43,55 170 PLOT 40,60 130 PLOT 37,65 190 DRAWTO 43,65 102 200 PLOT 40,70 210 DRAWTO 40, 100 220 DRAWTO 45, 100 230 DRAWTO 35, 100 240 DRAWTO 40, 100 250 DRAWTO 40, 130 260 DRAWTO 45, 140 270 DRAWTO 40, 130 280 DRAWTO 35, 140 300 GOTO 300 83 Okay, Now Wave This is a development of the stick man drawn and frozen on the screen in Tip Number 82. Here, we add pro- gram lines to draw and seem to move the stick man's left arm on the right side of the TV screen. This program is the same as the previous program, through line 280. Change line 300 and add what we show here through line 430. Here's how it works to create the il- lusion of arm movement: Lines 300 to 320 draw the arm in an upward position. Line 330 is a time-delay pause so you have time to see the arm in an upward position. Lines 340 to 360 erase the same arm. Lines 370 to 390 draw a downward arm. Lines 400 to 420 erase the downward arm. Line 430 makes everything start over again with the upward arm. The result is the ap- pearance of arm motion. Very clever, these stick men! Program Listing 10 < 5RAPHICS ? 20 " COLOR 8 100 PLOT 3f >,5G 1 110 DRAWTO 45, 50 120 DRAWTO 45, 70 130 DRAWTO 35, 70 140 DRAWTO 35, 50 103 150 PLOT 37,55 160 PLOT 43,55 170 PLOT 40,60 180 PLOT 37,65 190 DRAWTO 43,65 200 PLOT 40,70 210 DRAWTO 40, 100 220 DRAWTO 45, 100 230 DRAWTO 35, 100 240 DRAWTO 40, 100 250 DRAWTO 40, 130 260 DRAWTO 45, 140 270 DRAWTO 40, 130 280 DRAWTO 35, 140 300 COLOR 8 310 PLOT 45, 100 320 DRAWTO 50,85 330 FOR T~l TO 200 s NEXT T 340 COLOR 350 PLOT 50,85 360 DRAWTO 45, 100 370 COLOR 8 380 DRAWTO 50, 115 390 FOR T=l TO 200 "NEXT T 400 COLOR 410 PLOT 50, 115 420 DRAWTO 45, 100 430 GOTO 300 84 Moving* Illusion Beware! This constantly-moving image may drive you batty. Program Listing 10 PRINT " }" sREM BUZZER 20 GRAPHICS 10 30 POKE 704,96 40 POKE 705,22 104 50 poke;: 7 06 1 38 60 POKE 7 07,54 70 POKE 7 03,70 80 POKE 7 $9,86 90 POKE 7 10, 104 100 POKE 7 1 1 , 1 20 110 POKE 712,1 80 120 FOR X =1 TO 64 130 LL=19 1~X5LR=79~X 140 M=M*< M<8)+1 150 COLOR M 160 PLOT X , X 170 DRAWT X,LL 180 DRAWT LR,LL 190 DRAWT LR, X 200 DRAWT X , X 210 NEXT Y 220 a=pee; K(712) :E^=PEEK ( 7 1 1 ) : C= = PEEK ( 7 1 ) 230 D=PEEI •((709) :E=PEEK (703) !F= = PEEK (707) 240 G=PEEK(706) :H=PEEK (705) 250 POKE 712, B 260 POKE 7 1 1 , C 270 POKE 7 1 , D 280 POKE 709, E 290 POKE ■ 708, F 300 POKE 707, G 310 POKE 706,14 320 POKE 705 , A 330 GOTO : 220 85 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 20 GRAPHICS 10 30 POKE 704,96 40 POKE 705,22 50 POKE 706,38 60 POKE 707,54 70 POKE 708,70 POKE 709,86 POKE 710, 104 POKE 711 , 120 BUZZER 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 32© 330 340 35(3 360 370 POKE 712, 180 FOR X=l TO 64 LL=191-XsLR=79- M=M* :F= PEEK (7 10) PEEK (707) G=PEEK ( 706 ) s H=PEEK ( 705 ) 7 1 2 , B 711, C 7 1 , D POKE POKE POKE POKE POKE POKE POKE POKE J=j+i POKE 704 IF J=255 GOTO 230 ? 09, ■08. ? 07. •'06 , '05. E F G H A J THEr \ J=l 106 86 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= I NT ( 320* < RND ( 1 ) ) ) 50 Y=INT< 192*(PND(1 ) ) ) 60 DRAWTO X,Y 70 GOTO 40 87 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 GRAPH I' IS 8+ 16 20 X-319;'' r'=S »6 30 COLOR 40 PLOT X- -2(2 ) i Y 50 DRAWTO X- ■10 , Y- -10 60 DRAWTO X, Y+ 10 70 DRAWTO x- -10 ,Y 80 DRAWTO X, Y-- 10 90 DRAWTO X- 10 , Y+10 100 DRAWK '.) X , V 110 X=X~10 120 IF X<21 THEN 300 130 COLOR 255 107 140 PLOT X-20, Y 150 DRAWTO X-10,Y 10 160 DRAWTO X, Y+10 170 DRAWTO X 10, Y 180 DRAWTO X,Y--10 190 DRAWTO X 10, Y+10 200 DRAWTO X-20,Y 210 GOTO 30 300 PRINT "END OF SWIM" OO Circling Dot More round graphics on your rectangular picture tube. Program Listing 10 GRAPHICS 3+16 20 FOR H-t TO 12 30 COLOR 1 40 PLOT 20, 10 50 X=*2®-< 10*COS(N/6*3„ 14) ) 60 Y=10+< 10*SIN(N/6*3, 14) ) 70 PLOT X,Y 80 FOR T=l TO 50 3 NEXT T 90 COLOR 100 PLOT X,Y 110 NEXT N 120 GOTO 20 89 Box The Screen Here's how to draw a box around the graphics display-screen area on your TV monitor. Lines 30 to 70 draw the vertical sides of the box while lines 80 to 120 draw the horizontal bottom and top. Line 130 is a freeze- frame loop to hold the picture so you can see it. 108 Program Listing 10 GRAPHICS} 3- !-16 20 COLOR 1 30 FOR Y=0 TO 23 STEP 23 40 FOR X=<3 TO 39 50 PLOT X , Y 60 NEXT X 70 NEXT Y 80 FOR X=0 TO 39 STEP 39 90 FOR Y=0 TO 23 100 PLOT X,Y 110 NEXT Y 120 NEXT X 130 GOTO 130 90 Window Twinklers Well, what would you call them? Program Listing 10 GRAPHICS 3+16 20 COLOR 1 30 FOR Y=0 TO 23 STEP 2 40 FOR X-0 TO 39 50 PLOT X,Y 60 NEXT X 70 NEXT Y 80 FOR X = TO 39 STEP 3 90 FOR Y=0 TO 23 100 PLOT X,Y 110 NEXT Y 120 NEXT X 130 C=INT(5*(RND< 1 ) ) ) 140 COLOR C 150 X=INT(40*(RNIJ '38 THEN 170 Y=INT< 24*22 THEN 170 19(3 PLOT X,Y 200 GOTO 130 91 Horn-ln-Funnel Art The background color keeps changing. Program Listing 10 GRAPHICS 10 20 FOR Z=l 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=l 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,LL 190 DRAWTO LR, X 200 DRAWTO X, X 210 NEXT X 220 NEXT Z 230 GOTO 230 92 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. 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 93 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=l TO 84 30 PRINT #6, "*" 5 40 NEXT L 50 GRAPHICS 60 GOTO 10 94 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. 111 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 T=l TO 50 : NEXT T 60 COLOR © 70 PLOT X, 10 80 NEXT X 90 GOTO 20 95 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 96 Luminance Demonstrator Take a look at 116 shades of a color! 112 Line 10 selects graphics mode 9 which permits 116 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 SET COLOR 4,6,0 30 FOR X=0 TO 15 40 COLOR X 50 PLOT X,0 60 DRAWTO X, 191 70 NEXT X 30 GOTO 80 97 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, then left to right, leaving a dark horizon- tal 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=l TO 50 ! NEXT T 60 COL. 'OR 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~® TO 23 20 FOR X= ; TO 3? 30 COLOR 65 40 PLOT X,Y 50 FOR T-l TO 50 " NEXT T 60 COLOR 70 PLOT X, 10 80 ME XT X 35 NEXT Y 90 GOTO 90 98 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 10.1.0 FOR L=l 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 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: PRINT #6" PRINT #6 30 PRINT #6?" TITLE" 40 PLOT 1 , 1 50 DRAWTO 19, 1 60 DRAWTO 19,4 70 DRAWTO 1,4 80 DRAWTO 1 , 1 100 GOTO 100 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 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 PRINT "1978 PROFITS: '• , : INPUT A 20 PRINT "1979 PROFITS : " , : INPUT E 30 PR I N T " 1 9 B P R F ITS:", 1 1 1\| p U T C 40 PRINT "1981 PROFITS:" ,: INPUT D 50 PRINT "1982 PROFITS :",: INPUT E 100 GRAPHICS 2+16 120 PRINT #6? " PROFITS" 130 PRINT #6 200 PRINT #6; " 1978" 210 PLOT 6,2 220 DRAWTO 6+A,2 230 POSITION 0,4 300 PRINT #6;" 1979" 310 PLOT 6,4 320 DRAWTO 6+E , 4 330 POSITION 0,6 400 PRINT #6? " 1980" 41(3 PLOT 6,6 420 DRAWTO 6 + C6 430 POSITION 0,8 500 PRINT #6? "1981" 510 PLOT 6,8 520 DRAWTO 6+D,S 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 101 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 i STEP 16 •NEXT T 1000 GRAPHICS 10 10.10 FOR L-15 TO 25 1020 POKE 704 , L 1030 FOR T=l TO 100 1040 NEXT L 1050 GOTO 1010 117 Appendix Appendix A: ATARI BASIC Words Here is a handy list of all the words in the ATARI ver- sion of the BASIC computer language: ABS absolute value function ADR string memory address function AND logical expression true only if both are ASC finds ASCII character number ATN arctangent BYE leave BASIC; write directly on screen CLOAD load program from tape CHR$ converts ASCII number to character CLOG base 10 logarithm CLOSE close file at end of I/O job CLR undimensions strings and arrays COLOR select color register for graphics COM same as DIM CONT continue, after BREAK or STOP COS cosine CSAVE sends data from computer to tape DATA 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; 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 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 ATARI 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 the device is turned off, dummy 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 books from ARCsoft Publishers For the TRS-80 PC-1, PC-2, Sharp PC-1211, PC-1500: 99 Tips & Tricks for the New Pocket Computers (PC-2/PC-1500) 128 pages $7.95 ISBN 0-86668-019-5 101 Pocket Computer Programming Tips & Tricks 128 pages $7.95 ISBN 0-86668-004-7 Pocket Computer Programming Made- Easy 128 pages $8.95 ISBN 0-86668-009-8 Murder In The Mansion and Other Computer Adventures 96 pages $6.95 ISBN-0-86668-501-4 50 Programs in BASIC for Home, School & Office 96 pages $9.95 ISBN 0-86668-502-2 50 MORE Programs in BASIC for Home, School & Office 96 pages $9.95 ISBN 0-86668-003-9 35 Practical Programs for the Casio Pocket Computer 96 pages $8.95 ISBN 0-86668-014-4 Pocket-BASIC Coding Form programming worksheet tablets 40-sheet pad $2.95 ISBN 0-86668-801-3 For the TRS-80 Color Computer: 101 Color Computer Programming Tips & Tricks 128 pages $7.95 ISBN 0-86668-007-1 55 Color Computer Programs for Home, School & Office 128 pages $9.95 ISBN 0-86668-005-5 55 MORE Color Computer Programs for Home, School & Office 112 pages $9.95 ISBN 0-86668-008-X Color Computer Graphics 128 pages $9.95 ISBN 0-86668-012-8 The Color Computer Songbook 96 pages $7.95 ISBN 0-86668-01 1-X My Buttons Are Blue and Other Love Poems 96 pages $4.95 ISBN 0-86668-013-6 Color Computer BASIC Coding Form program worksheet tablets 40-sheet pad $2.95 ISBN 0-86668-802-1 For the APPLE Computer: 101 APPLE Computer Programming Tips & Tricks 128 pages $8.95 ISBN 0-86668-015-2 33 New APPLE Computer Programs for Home, School & Office 96 pages $8.95 ISBN 0-86668-016-0 APPLE Computer BASIC Coding Form program worksheet tablets 40-sheet pad $2.95 ISBN 0-86668-803-X For the ATARI 400 and 800 computers: 101 ATARI Computer Programming Tips & Tricks 128 pages $8.95 ISBN 0-86668-022-5 31 New ATARI Computer Programs for Home, School & Office 96 pages $8.95 ISBN 0-86668-018-7 ATARI Computer BASIC Coding Form program worksheet tablets 40-sheet pad $2.95 ISBN 0-86668-806-4 127 books from ARCsoft Publishers For the Sinclair ZX-81 and TIMEX/Sinclair 1000 computers: 101 TIMEX 1000 and Sinclair ZX-81 Programming Tips & Tricks 128 pages $7.95 ISBN 0-86668-020-9 37 TIMEX 1000 & Sinclair ZX-81 Programs for Home, School & Office 96 pages $8.95 ISBN 0-86668-021-7 TIMEX 1000 & Sinclair ZX-81 BASIC Coding Form program worksheets 40-sheet pad $2.95 ISBN 0-86668-807-2 For the electronics hobbyist: 25 Quick-N-Easy Electronics Projects 96 pages $4.95 ISBN 0-86668-023-3 25 Electronics Projects for Beginners 96 pages $4.95 ISBN 0-86668-017-9 25 Easy-To-Build One-Night & Weekend Electronics Projects 96 pages $4.95 ISBN 0-86668-010-1 Computer program-writing worksheets: Each in tablet of 40 sheets with stiff backing Universal BASIC Coding Form $2.95 IBM Personal Computer BASIC Coding Form $2.95 ATARI Computer BASIC Coding Form $2.95 Pocket Computer BASIC Coding Form $2.95 APPLE Computer BASIC Coding Form $2.95 Color Computer BASIC Coding Form $2.95 TIMEX 1000/Sinclair ZX-81 BASIC Form $2.95 ISBN: International Standard Book Number ARCsoft Publishers Post Office Box 132 Woodsboro, Maryland 21798 128 ATARI Computer Book II 101 ATARI Computer Programming Tips & Tricks by Alan North Here's a giant collection of practical, useful, efficient program- ming techniques and operating shortcuts, for the ATARI model 400, 600 and 800 personal computers, right out of a master programmer's notebook. Loaded with hints, secrets, tips, tricks and easy-to-follow instruc- tions, this book shows you how to handle routine programming chores on the Atari 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 instruc- tions to your computer. All 101 programs have been tested thoroughly on the ATARI 400/800 Computer and are ready to type in and run. 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 computer programmer's handbook of tips and tricks. ARCsoft Publishers Woodsboro, Maryland ISBN 0-86668-022-5