12.07.2015 Views

page-1983-101-timex-sinclair-programming-tricks

page-1983-101-timex-sinclair-programming-tricks

page-1983-101-timex-sinclair-programming-tricks

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

IMEX/ SJ,NCLAIRODO zx-B'IRDGRAMMINGTIPS & TRICKS


TIMEX/ SINCLAIR,~coo zx-e1 IPROGRAMMINGTIPS & TRICKSby Edward PageARCsoft PublishersWOODSBORO, MARYLAND


FIRST EDITIONFIRST PRINTING©<strong>1983</strong> by ARCsoft Publishers, P.O. Box 132, Woodsboro, MD 21798 USAPrinted in the United States of AmericaReproduction or publication of the contents of this book, in any manner,without express permission of the publisher, is prohibited. No liability isassumed with respect to the use of the information herein.Library of Congress (LC) number: 82-18413Trademark credits and software copyrights:Sinclair ZX-81 is a trademark of Sinclair Research Ltd.Timex-Sinclair 1000 is a trademark of Timex Computer Corp.Programming advice and applications software in this bookare Copyright <strong>1983</strong> by ARCsoft PublishersISBN 0-86668-020-9


PrefaceThe Sinclair ZX-81 and Timex/Sinclair 1000 are themost popular personal computers in the world. As of thiswriting more of those models have been sold than anyother computer in history.The very light weight and highly portable design ofSinclair's computer, coupled with the powerful version ofthe BASIC <strong>programming</strong> language it uses, have placed itat the very forefront of the new wave of computers forhome, school and office.Anything but a toy, the hardware configuration of theTIS 1000 and ZX-81, and its versatile system software,make it a highly useful tool in the business environmentand the classroom as well as for practical jobs around thehome.In fact, the system software is so flexible that theneed for this book became apparent. There are so manycomputer tasks which can be accomplished with theZX-81 and TS/1000 that an introduction to the manytechniques is needed.Software programs are what make a computer dowork for you. This book is written for those newcomersand beginners, as well as advanced novices and studentprogrammers, who would like to tap the seeminglyunlimitedresources in the TIS 1000 and ZX-81 computerpackage. It is hoped this book will guide and instruct andprovide insights into the many ways the BASIC languagein Sinclair's machine can be put to use.This book is a companion volume to 37 TIMEX1000/Sinclair ZX-81 Programs for Home, School & Office.~Edward Page


TipTable of ContentsPageIntroduction 11Fun & Games1 Coin Toss 182 Traditional Dice Roll 183 See Two Dice 194 See Four Dice 205 Secret Message I 216 Secret Message 11 217 Up, Down, Back, Forth 228 Drawing Sketches 239 Mystery Clues 2410 Original Hi/Lo Game 2511 Code Groups 2612 60-Second Ti mer 2713 Find Highest/Lowest 2714 Door Opener 2815 Keeping Game Scores 2916 Batting Average 3017 Computer Rating Service 3118 Box Score 32


Text on Text19 Create a Quiz 3620 Killing Time 3721 Word-Error Trapping 3722 Character Numbers 3823 One-Time Password 3924 Three-Tries Password 3925 Multiple Passwords 4026 Memory Review 4127 Entering: Letter Stop 4228 Entering: Zero Stop 4229 Superior Decision Maker 4330 Stopwatch 4431 Wipeout! 4532 Sentence Writer 4633 Categorizing 4734 Alphabet Soup 4835 Letter Repeaterrrr 4936 Question & Answer 50


Gee Whiz37 Gee Whiz I: Smart Adder 5538 Gee Whiz II: Three-Digit Mystery 5639 Gee Whiz Ill: Yes/No Decision Maker 5640 Gee Whiz IV: First Alphabet Spotter 5741 Gee Whiz V: Second Alphabet Spotter 5842 Gee Whiz VI: Guess The Number 58Number Chrunching43 Memory Tester 6344 Number Reverser I 6445 Number Reverser II 6546 Number-Error Trapping 6547 Standard Deviation 6648 Percentages 6749 Logic Functions 6850 Above & Below a Line 6951 Factoring 7052 Which is Smallest? 7153 Which is Largest? 7254 Reciprocals 7355 Dump the Integer 7356 Averages 7457 Mid-Range Number 7458 Rounding Off 7559 Two-Digit Round Off 7660 Percent to Decimal 7761 Every 10th Answer 7762 Random Sampler 7863 Random Numbers: Zero To Nine 7964 Random Numbers: Distribution 8065 Random Numbers: Averages 8166 Random Numbers: Sorting High/Low 82


Money Matters67 Money Grows68 Shopper's Friend69 Car Payments70 To Nearest 95 Cents71 To the Nearest Penny72 Mark Up73 Percentage Off74 Doi lars & Cents75 Wages & Hours76 Invoicing77 Unit Price78 Bubble Sort79 Daily Code86878990919293939495969798Graphics80 Screen Full81 Sine Wave82 Hold That Pose83 Okay, Now Wave84 Create A Table85 Go To Black86 Centered Message87 Beautiful Braided Rug88 Circling Dot89 Making Things Move90 Window Twinklers91 Eyeball Scrambler92 Flashing Dot93 Snowfall94 Draw A Box I95 Draw A Box II96 Painting Exercises1031031031041051061071081081081091091<strong>101</strong><strong>101</strong>11111112


97 Draw A Line98 Box Message99 Boxed Title100 Draw Bar Graphs<strong>101</strong> Random Bar Graph112113114115117ABBASIC WordsError MessagesAppendix121125


IntroductionThere is a great need for practical, useful softwarefor the new generation of popular personal computers.The Sinclair ZX-81 and TIMEX/Sinclair 1000 computers,for example,are among the world's most popular. In fact,based on numbers sold they must be the most popular.The TIS 1000 and the ZX-81 are the same computer,except the T/S 1000 has more built-in memory than theZX-81. All <strong>101</strong> progams in this book have been written andtested on both computers and will run in the more-limitedZX-81 memory size. In other words, all of the programs inthis book will run on either machine.The TIS 1000 and the ZX-81 are powerful and versatileand flexible-but what can they do? Once you've purchasedthe hardware, you need down-to-earth ideas andworkable programs to make the computer work for you.The aim of this book is to provide more than <strong>101</strong> newand different ideas about how to use the computer andmore than <strong>101</strong> complete, ready-to-type-and-run programsyou can put to use immediately.11


The <strong>101</strong> programs in this handbook can stand aloneor be used as parts of larger sets of instructions youmight write. These are designed to be typed in, just asyou find them in this book, with no other <strong>programming</strong>needed.These programs are useful in themselves. They alsomake good Slarting points for further development as youlearn more a.bout how to program your own computer andstart to write more and more of your own programs. Youcan use these fun and practical programs and thenthem and expand them to suit your needs as theygrow.This book can be used by newcomers and beginnersas well as by novices and students and more-advancedfolks who are in need of new ideas. Amidst our <strong>101</strong> ·tipsare many, many secrets, shortcuts, <strong>tricks</strong>, hints, techniquesand make-it-easier instructions, each designed tomal{e you a more versa.tile programmer and to make your<strong>programming</strong> effort lighter. Use this book to stimulateyour thinking about how to approach various softwareproblems. Use it to get good ideas for new and differentapproaches to all your <strong>programming</strong> goals.We make the assumption that you know how to setup your TIS 1000 or ZX-81 (or MicroAce) for use. You knowhow to connect the cab!e between the TV switchbox andthe computer. You know how to plug the power supply intoa wall socket and attach the power cord to the computer.You know how to type on the flat keyboard, locatethe shift key, and obtain the various "levels" of functionson the multiple-function keys. If you don't have theseareas of skill down pat, yet, check your owner's manuaLThe Sinclair ZX-81 manual is entitled, ZX-81 BASIC Programmingand is thorough. The similar publication whichTIMEX ships with the TIS 1000 is the TIMEX User Manual.Please review these thoroughly as you start to use theprograms in this book.You do not have to be a programmer to use the softwarein this book. Just type in the programs as you findthem here and run them. They will work!A major part of your learning from this book willcome as you go through the work of typing in these programsmaking sure you have each line typed correctly. If a12


error, or other error, occurs, go back and makesure your typed iine matches what we have nted in thisbook. Our program lines are believed to be exactly cor·rect Ali have been tested on a TIS 1000 and a ZX·Bi andwork properly.If, after typing in a program line as we have it, you getan error message from your computer, check the handylist of error messages in the Appendix at the rear of thisbook. You also will find a convenient list of BASiC words,as used in the T/S 1000 and ZX 81, in the Appendix.If you are getting an error message, most i youwill find you have made a typographical error in typing theprogram into the computer. However, should you find atypo which we may have made in this book, please let theauthor know. Send a postcard or letter to the author incare of ARCsoff Publishers, P.O. Box 132, Woodsboro,MD 21798 USA. The author will appreciate being abie tomake any necessary corrections to future editions.Home, school and ofHc~The book has been organized into several sectionsplus an appendix. The first section includes tips and<strong>tricks</strong> which you may find applicable to writing and play·ing games with your computer.Other sections will advance your knowledge of howthe computer handles text, works with numbers, createsgraphics designs on the TV screen, etc. Naturally, thesections of the book, as divided, are not rigid and exclusive.You probably will find something in the graphicssection to add to a "money matters" program. Or a "text"tip could easily be applicable to a game. You might findlots of additional "gee whiz" programs in other sectionsof the book.Try them all. They're great fun to run. And they areespecially designed to be short so you won't have tospend hours typing in one program.REM arksAs you read through the <strong>101</strong> programs in this book,you will notice few REM, or remarks, statements. The13


author's training in writing BASIC-language computerprograms included an emphasis on brevity and savingmemory space. A sharp editing pencil was in order~andstill is!With only one to two kilobytes (1 k to 2k) of memoryavailable in the ZX-81 or TIS 1000, you need to create leanprograms. There is no room for fat~and this is good! Programmerswho have learned on such systems will makebetter professionals because they know how to write efficient"code."REMarks and explanations in software are out. Honing,fine-tuning and waste trimming are in. Use of codingform program worksheets, such as the TIMEXUJOO/Sinclair ZX-81 BASIC Coding Form published byARCsoft Publishers, is encouraged. The objective alwaysis to make the most efficient use of available memory.Always remember: even though they may be headedtoward the same goal, no two programmers will write exactlythe same list of BASIC instructions, or programlines, from scratch. As you load these <strong>101</strong> programs intoyour TIS 1000 or ZX-8i computer, one at a time, you willmake modifications to suit your personal needs and interests.Exact wording of PRINT statements, for instance,can be changed. Or, two or more programs can be combinedinto one grand scheme. Your application may vary.If you want to load more than one of these programsinto your TIS 1000 or ZX-81 at the same time, be sure touse different sets of line numbers for different programs.Two programs can't occupy the same set of line numbersat the same time!ENTER vs, RETURNComputer programmers today generally mix the twowords, RETURN and ENTER, together and use them tomean the same thing. in either case, when you seeRETURN or ENTER in this book, we mean the ENTER keyon the right-hand side of the ZX-81 or TIS 1000 keyboard.These programs will run on any computer which canbe programmed in BASIC. However, to run on machinesother than the TIS 1000 or ZX-81, you will have to makel4


slight modifications to program lines. Graphics commands,especially, will differ on non-Sinclair computers.Refer to the owner's manual which came with yournon-Sinclair computer and compare its version of BASICwith the Sinclair BASIC. A list of Sinclair BASIC wordscan be found in the Appendix at the end of this book.Also, if you use a computer other than T/S 1000 orZX-81, such things as line numbering, logical tests,multiplication symbols., print statements and other instructionsmay differ.Report codesSinclair refers to its error messages as report codes.We refer to them as error messages because that's howmost programmers today would refer to them. Reportcodes and error messages are the same thing in thisbook.Many of the programs in this book will continue torun until you command them off via the BREAK key. Youmay stop any run, at any time, with the BREAK key at thelower right-hand side of the keyboard.The author would like to have your suggestions forchanges in future editions of this work, or for other booksin this series for the TIMEX/Sinclair 1000 and SinclairZX-81 computers. He may be addressed in care of ARCsoftPublishers.Good <strong>programming</strong>!15


Fun & Games


1 Coin TossHere'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 reportheads or tails after each toss.For a new toss, press any key on your computer'skeyboard.Line 20 clears the screen. A random number is generatedat line30.Lines 60 and 70 accomplish the restart whenyou press any key .Program Listing10 RAND20 CLS30 LET R=RND40 IF R.5 THEN PRINT •TAILS•60 IF INKEY$=•• THEN GOTO 6070 GOTO 202 Traditional Dice RollHere's a simple, brief way to roll and display resultsfor two dice.Lines 100-110 get a random number between 1 and 6and store it in A. Lines 200-210 get another randomnumber from 1 to 6 and store it in B.Lines 300-310 print the contents of A and B alongwith a suitable message. Lines 400-420 cause the computerto await the press of any key on its keyboard. Whena key is pressed, dice are rolled and new resultspresented on the video display.18


Program Listing10 RAND100 LET A=INT(lO*RND)110 IF A6 THEN GOTO 100200 LET B=INT(lO*RND)210 IF B6 THEN GOTO 200300 PRINT "FIRST DICE: ",A310 PRINT "SECOND DICE: ",B400 IF INKEY$="" THEN GOTO 400410 CLS420 GOTO 1003 See Two DiceHere's a quick way to add real dice to any fun programyou are designing for your computer.This program rolls two dice and lets you see theresults, as with real dice. This is especially useful inthose games where it is important to see the value ofeach.The subroutine in lines 100-140 generates thenecessary pair of random numbers. Lines 60, 70 and 80make the display you want.Note that lines 60 and 80 each have nine asterisks.Line 150 is RETURN and must be the last line in the program.After you type in and RUN the program, press any keyon your computer's keyboard to roll the dice.Program Listing10 CLS20 PRINT"TO ROLL 2 DICE, PRESS ANY KEY"30 IF INKEY$="" THEN GOTO 3040 CLS50 GOSUB 10060 PRINT"*********"70 PRINT"* ";L;" * ";R;" *"19


80 PRINT"*********"90 PRINT95 GOTO 20100 RAND110 LET L=INT(7*RND)120 IF L


140 IF R


stance: I WENT TO THE STORE comes out EROTS EHTOT TNEW I.Program Listing10 CLS20 PRINT •WHAT IS THE MESSAGE ?"30 INPUT A$40 LET L=LEN A$50 FOR J=L TO 1 STEP -160 PRINT A$ (J);70 NEXT J80 PRINT90 GOTO 207 Up, Down, Back, Forth"Good golly, what can't that computer do?", will bethe question from your surprised neighbor when youshow him this neat trick.You type in any word. The computer instantly prints iton the video display, both up and down vertically, andbackward and forward horizontally. It's great to show howsmart your computer is when it comes to spelling!Program Listing10 PRINT "GIVE ME A WORD"20 INPUT A$30 CLS40 LET L=LEN A$50 PRINT •noWN:","UP:"60 FOR J=l TO L70 PRINT A$(J),A$(L+l-J)80 NEXT J90 PRINT100 PRINT 11 FORWARD: 11110 PRINT A$120 PRINT22


130 PRINT •BACKWARD:•140 FOR J=L TO 1 STEP -1150 PRINT A$(J);160 NEXT J170 IF INKEY$=•• THEN GOTO 170180 CLS190 GOTO 108 Drawing SketchesNow you can draw lines, rules, diagrams, maps, charts,boxes-anything you can imagine-on the face of yourTV set. Use the Computer keyboard as your penand its video output as your ink.Lines 120 to 150 accept your up, down, right, or leftcommands, as U, D, R, or L. No other letters will work.Line 200 draws your lines.Program Listing10 CLS20 LET X=3230 LET Y=2240 PLOT X,Y100 LET A$=INKEY$110 IF A$=•• THEN GOTO 100120 IF A$=•o• THEN LET Y=Y+l130 IF A$=•0° THEN LET Y=Y-1140 IF A$="R" THEN LET X=X+l150 IF A$="L" THEN LET X=X-1200 PLOT X,Y210 LET A$=••220 GOTO 10023


9 Mystery CluesWant to create your own murder mystery? Figure outwhodunit and write your program backwards from there.When your players make wrong guesses, give them tantalizingclues.Here's a short program which you can load into yourcomputer in a matter of minutes. Key it in and try it out. Itshows how you can add clues to your mysteries.For simplicity, we assume here the Butler did it. Notethat, in line 20, we are making him equal to X$. At line 30,the computer stops to ask you whom you think did it. Youranswer is recorded in A$.In line 40, your answer, lodged in A$, is comparedwith the computer's already-certain knowledge that theButler did it. A$ is compared with X$. If they agree, andonly if they agree, the computer displays the message,"You guessed it." If you got it right, things will end rightthere.If, however, you missed it, program execution (sorryabout using that word in a murder mystery!) drops to line50 where we hear the computer, "Clue: servant." Afterdeftly dropping that clue, the computer moves back toline 10 and runs through the whole affair another time. Itwill keep running through it until you answer, "Butler," inresponse to its question in line 30.Program Listing10 CLS20 LET X$=•BUTLER"30 PRINT •WHODlOJNIT ?•35 INPUT A$40 IF X$=A$ THEN GOTO 10045 CLS50 PRINT •cLUE: SERVANT•60 FOR T=l TO 10070 NEXT T80 GOTO <strong>101</strong>00 PRINT •you GUESSED IT: BUTLER.24


110 PRINT •PRESS ANY KEY TO PLAY AGAIN•120 IF INKEY$=•• THEN GOTO 120130 GOTO <strong>101</strong>0 Original Hi/Lo GameHere it is. Where everybody started in microcomputer<strong>programming</strong> back in the Seventies. The firstgame ever played was a high-low guess-the-numberroutine.The computer selects a secret number. You· try toguess it. The computer tells you whether or not you aretoo high, too low, or right on the number.Here's how it works: the secret number can be zeroto 999. Line 100 generates a random number (the secretnumber) and stores it. Line 210 asks you to guess thenumber.Lines 300-310 decide if you are right or wrong. Line230 keeps track of the number of attempts.Program Listing10 LET T=jf20 RAND100 LET R=INT(lOOO*RND)200 PRINT •GUESS THE NUMBER 0210 INPUT B220 CLS230 LET T=T+l240 PRINT 0 THAT WAS TRY NUMBER • :T300 IF B>R THEN GOTO 400310 IF B


600 PRINT.610 PRINT "****************"620 PRINT R;" IS THE NUMBER"630 PRINT "****************"640 PRINT "YOU GOT IT IN ";T;" TRIES"700 IF INKEY$="" THEN GOTO 700710 CLEAR720 CLS730 GOTO <strong>101</strong>1 Code GroupsNeed some secret codes for your latest sensitivemission? How about sets of five random letters for use inMorse code practice?This program has the computer generate an endlessstring of random combinations of five letters. It won't stopuntil you press the BREAK key.Program Listing10 RAND20 LET A$="ABCDEFGHIJl


12 60-Second TimerA one-minute timer can be very handy for fun-ngames.This easy-to-use clock counts off seconds upto 60.The number of seconds counted can be changed bychanging the number 60 in line 40.The clock can be calibrated by changing the number6 in line 60. Line 60 is a time-delay loop set for approximatelyone second.Program Listing10 CLS20 PRINT30 SCROLL40 FOR T=l TO 6050 PRINT T:" SECONDS"60 FOR L=l TO 670 SCROLL80 NEXT L90 NEXT T100 PRINT "END OF TIME"13 Find Highest/LowestSuppose we have a list of people and each person hasbeen assigned a number or score. This program acceptsthe scores and sorts out the persons with the highestand lowest scores. Here's how it works.· Lines 30-130 take in the info on each person.As each person's score is entered, lines 100-120 determineif it is higher or lower than all previous scores. Ifhigher or lower, it is so noted.To complete data entry, simply press ENTER withoutdata. That will prompt the computer, at lines 140 and 150,to print the lowest score and the highest score.27


Program Listing10 LET N=f,J20 PRINT •scoRE:"30 INPUT K$40 IF K$=•• THEN GOTO 13050 PRINT K$60 LET N=N+l70 LET K=VAL K$80 IF N=l THEN LET L=K90 IF N=l THEN LET H=K100 IF K>H THEN LET H=K110 IF K


210 IF A$=•• THEN GOTO 200220 IF A$="o• THEN GOTO 300230 IF A$=•c• THEN GOTO 100240 GOTO 200300 FOR X=21 TO 24310 FOR Y=21 TO 29320 UNPLOT X,Y330 NEXT Y340 NEXT X350 FOR Y=21 TO 29360 FOR X=21 TO 24370 UNPLOT X,Y380 NEXT X390 NEXT Y400 GOTO 20015 Keeping Game ScoresWriting a computer football game? Spelling bee?Cave adventure? No matter what kind of fun you arepreparing, you'll need a way to keep score. Here's how.The wealthy English duke has just been killed in ourlittle mystery game. In lines 10 through 160 ofour program listing, below, you play the game, attemptingto find out whodunit.The trick here is in the scorekeeping. Noteline170.lfyou guessed correctly in response to the query in line160,at line170 the computer will give you credit by adding onepoint to your score stored in memory location R. It doesthat by comparing your line160 answer stored in P$ withthe correct answer stored in A$·.If you blew it and guessed wrong, the program dropsbelow line170to line 180 where it increases your "wrongscore" by adding one point to W.If you got a W+1 at line 19_Q, the program moves backtoline120and gets you to try again. If you scored avictoryand got an R+1 at line 170, the program jumps to line 200where it stops to display your total right and wrong score.29


After that, it's back to line 10 for a complete new runthrough.Program Listing10 CLEAR15 LET W=JJ20 LET R=JJ25 DIM 1\.$(6,7)30 DIM P$(7)35 LET S=INT(lO*RND)40 IF S6 THEN GOTO 3060 LET A$(l)="BUTLER"70 LET A$(2)="NANNYn80 LET A$(3)=•MAID"90 LET A$(4)=•soNn100 LET A$(5)=•coACH"110 LET A$(6)=•wIFEn120 PRINT "WHO KILLED THE DUKE?n130 PRINT •wAS I~ THE ••• •140 FOR L=l TO 6145 PRINT A$(L)150 NEXT L160 INPUT P$165 CLS170 IF A$(S}=P$ THEN GOTO 200180 PRINT "NOT ";P$190 LET W=W+l195 GOTO 120200 LET R=R+l210 PRINT P$;" DID ITn220 PRINT •youR SCORE IS ••• •230 PRINT R;• RIGHT •;w;• WRONGn240 PRINT250 GOTO <strong>101</strong>6 Batting AverageOnce you know the number of times you were rightand wrong in a game, as in Tip Number 15, it's fun to30


convert those raw numbers to a batting average. Numbersright and numbers wrong take on a new meaning whenchanged to a batting average. Folks seem to be able tounderstand a batting average better.Our program, starting at line 900, is a partial listingdesigned to be tacked onto the end of your longer gameprogram to display the final results of play. It will showthe number of tries, number of right answers, percentageright, and batting average.You'll want to test load this program so add lines 10and 800 as shown. Line 800 will give you the A and Tvalues you'll need going into the program at line 900.Program Listing10 CLS800 LET R=55810 LET T=lOO900 PRINT R;n RIGHTn910 PRINT nIN •;T;n TRIESn920 LET D=R/T930 LET P=lOO*D940 LET B=lO*P950 PRINT nTHAT IS •;p;• PERCENTn960 PRINT •BATTING •;B17 Computer Rating Servic,eOf course, once you know a player's batting averageit still might need some interpretation. In this program,the computer takes a look at a batting average and makesa comment.Remember that this listing, starting here with line800, is a partial program to be tacked on the end of alonger game. Note that, at 800, you already have values forG (number right) and E (number of tries). Line 810 convertsthose raw numbers to a batting average (H).Then, the computer takes that batting average,stored in H, and compares it with values shown in lines31


830 to 870. Depending upon the value of H, a slogan isselected by a jump to one of the lines 880 to 950.By the way, check line 880. You'll see a specialepitaph for players with batting averages above 900.Program Listing10 Cl.$700 LET G=55710 LET E=lOO800 PRINT "YOU GOT ";G;" RIGHT IN °;E;" TRIES"810 LET H=INT(lOOO*(G/E))820 PRINT "BATTING ";H825 PRINT "YOU ARE ••• "830 IF H


The program here has a temporary substitute forlines 10-40. Normally, you would obtain player's name andscore from some larger game program you already haveon hand, or are writing. Line 20 gets from you a name andstores it in N$. Line 30 gets a score and stores it in S. Iflines 50-230 were a subroutine to a larger program, youwould need a RETURN at line 110.To try the highlighting technique, type in this programjust as it is here. All of it, from line 10 through line2:30, and RUN it. You'll see the name and score you givethe TIMEX displayed in a box on the video screen.,IProgram Listing10 DIM A$(10)20 PRINT •PLAYERS NAME ?•25 INPUT N$30 PRINT •PLAYERS SCORE ?"35 INPUT s40 CLS50 LET S$=STR$(S)60 LET L=LEN(N$)+LEN(S$)70 LET T=L+l380 GOSUB 20085 PRINT90 PRINT .* • ;N$; •s SCORE: ";S$;• *n100 GOSUB 200110 PRINT120 PRINT130 GOTO 20200 FOR L=l TO T210 PRINT n*n;220 NEXT L230 RETURN33


Text On Text


1 Create a QuizOne of the most fascinating uses for your TIMEX isin having it carry on a video conversation with yourfriends, 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 mo to 140. Be careful, when you typethem in. Spelling and spacing must be exactOf course, the quiz can be made much longer. In thisexample, it could be expanded to encompass all past U.S.presidents.Program lis~ing10 RAND20 DIM P${5.,10)100 LET P$(l)=~WASHINGTON.,110 LET JP$( ="'ADAMS"120 LET P$(3)="JEFFERSON~130 LET P${4)= 00 MADISON~140 LET P$(5}=~MOJNROE~200 LET R=INT(6*RND)210 IF R


20 Killing TimeSometimes, it may seem to you as if the computerwill never get to the result of a job. You understand theprocessing delay but your non-computer friends may not.They could be confused by the wait and think the computeris "broken."To keep their minds off the slowness, give themsomething to look at while the computer is "thinking."The added, extra lines, numbered 60 and 70,take up more processing time but make for less confusion.Computing may take a bit longer but your fun will beincreased.If you delete lines 60-.70 you'll see how the programruns faster but the blank screen is confusing.Program Listing10 LET X=j620 PRINT •GIVE ME A NUMBER"30 INPUT N40 FOR L=l TO N50 LET X=X+L60 CLS70 PRINT •I AM THINKING"80 NEXT L90 CLS100 PRINT •I HAVE THE ANSWER"110 PRINT •THE TOTAL OF ALL NUMBERS"120 PRINT •FROM 1 TO ";N;• IS •;x130 PRINT140 GOTO 1021 Word-Error TrappingThe same kind of error trapping is available forstrings. Suppose the program, as in this exa.mple, asks at37


line 10 for a.word. It is looking for YES or NO. If it gets aYES, then line 20 sees that it got what it wanted andmoves operations along to line 100.If it gets a NO, then line 20 hasn't received what itwants so program execution moves on to line 30. Here, atline 30, the program finds something useful and shootsoperations down to line 200.If, however, neither YES nor NO were entered at line10, then neither lines 20 nor 30 would be satisfied so actionwould drop to line 40. Here, the error is trapped bycommanding the operator to give one of the two correctanswers. Then, at line 50, the operation is returned to line10 for a new try at the correct input.Program listing5 PRINT wWANT TO PLAY AGAIN ?~10 INPUT A$20 IF A$="'YES'" THEN GOTO 10030 IF A$=~No~ THEN GOTO 20040 PRINT ~PLEASE ANSWER ONLY YES OR NOw50 GOTO 10l 0 0 PRH\lT A$110 STOP200 PRINT A$210 STOPCharacter NumbersThis brief program displays the value for eachkeyboard character, side-by-side with the character itstands for. You will be able quickly to tell what eachnumber prints.Une 40 is a timing loop to slow down the presentationso you c•m digest the information. To make it evenslower, increase the number in line 40. To make itfaster, decrease the number in line 40.38


Program Listing10 FOR L=f.J TO 255 STEP 2120 FOR N=L TO L+2130 PRINT N,CHR$ N40 PAUSE 6050 NEXT N60 CLS70 NEXT L23 One-Time PasswordIf you don't want unauthorized use of your programs,insert a requirement that a user know a password. Thisparticular routine allows only one try at entering a correctpassword.For our password, we have selected "elephant" andstored it in line 30. You can change the password towhatever you like.If a correct attempt at entering the password ismade, program action will progress to line 100. Otherwise,action drops to line 40 and action ends.Program Listing10 PRINT "WHAT IS THE PASSWORD ?"20 INPUT A$30 IF A$="ELEPHANT" THEN GOTO 10040 STOP100 PRINT "YOU GOT IT RIGHT"110 PRINT "A PROGRAM WOULD RUN"24 Three-Tries PasswordHere the software lets you try three times to enter thecorrect password. You don't get to go forward with the39


program if you. don't get it right in three tries.Again the password is "elephant" and is stored inline 30. You can change the password to whatever suitsyou.Lines 40 to 60 allow the three attempts. If no goodafter three tries, then end.Program Listing5 LET B=Jf10 PRINT •WHAT IS THE PASSWORD ? 020 INPUT A$30 IF A$= 0 ELEPHANTn THEN GOTO 10040 LET B=B+l50 IF B=3 THEN STOP60 GOTO <strong>101</strong>00 PRINT •you GOT IT RIGHT 0110 PRINT •A PROGRAM WOULD RUN"25 Multiple PasswordsHere's a really complex password entry system. Ithas a unique "account number" and a password for eachperson. This will allow several different persons access tothe program but each person will have a different combinationto the lock!accountnumber12345234563456745678passwordzebragoosetroutsnakeEach individual user must correctly enter his uniqueaccount number and then his own personal password. Ifaccount number is wrong, then the password never canbe right. If account number is okay but password doesn'tmatch, the user gets no run.40


You can add users to this program by adding lines tothe 300-340 subroutine.Program Listing10 FOR L=l TO 320 PRINT "YOUR ACCOUNT NUMBER ?"30 INPUT U40 GOSUB 30050 PRINT "PASSWORD ?"60 INPUT P$70 IF P$=W$ THEN GOTO 10080 NEXT L90 STOP100 PRINT "YOU GOT IT RIGHT"110 PRINT "A PROGRAM WOULD RUN"120 STOP300 IF U=l2345 THEN LET W$="ZEBRA"310 IF 0=23456 THEN LET W$="GOOSE"320 IF U=34567 THEN LET W$="TROUT"330 IF 0=45678 THEN LET W$="SNAKE"340 RETURN26 Memory ReviewThis useful program examines a range of memorylocations you specify and reports what it finds there. Itdisplays the memory location number alongside the con·tents, for convenience.Program Listing10 PRINT "SEARCH ROM MEMORY"20 PRINT "FOR CONTENTS FROM •••..n •30 PRINT "LOW ADDRESS: ,40 INPUT L50 PRINT Ln •60 PRINT "HIGH ADDRESS: ,70 INPUT H80 PRINT H41


90 PRINT100 PRINT "ADDRESS";TAB lO;"CONTENTS";TAB 20;"CHARACTER"110 FOR X=L TO H120 LET C=PEEK X130 PRINT X;TAB lO;C;TAB 20;CHR$ C140 NEXT X27 Entering: Letter StopOne way to conclude an input series, and get out ofits entry loop, is to use a key letter to promote a jump. Inthis brief example, we input numbers, at line 100, asstring values. If we give the computer an X rather than anumber, it will jump down to line 200 for new action.Numbers keyed in are stored first as strings. Thenline 120 changes them to number values for the additionin line 130.Program Listing10 LET B=JJ20 LET C=JJ30 PRINT "GIVE ME A NUMBER: ";100 INPUT A$110 IF A$="X" THEN GOTO 200115 PRINT A$120 LET B=VAL A$130 LET C=C+B140 GOTO 30200 PRINT210 PRINT220 PRINT "TOTAL OF NUMBERS = ";C28 Entering: Zero StopHere's another way to conclude an entry loop: havethe computer be on the lookout for a plain zero. When a42


zero is entered, the computer will jump out of the entry cycleand on to further action.This program totals numbers as they are added andaccumulates them in memory location B. If one of thenumbers entered is a zero alone, then line 110 will spot itand send the computer on down to line 200, breaking theentry cycle.Naturally, you can't use a zero in a string of numbersto be added since zero causes the computer to quit enteringand get on with displaying.Program Listing10 LET B=j20 PRINT nGIVE ME A NUMBER: •;100 INPUT A110 IF A=j THEN GOTO 200120 PRINT A130 LET B=B+A140 GOTO 20200 PRINT210 PRINT220 PRINT nTOTAL OF NUMBERS = ·~B29 Superior Decision MakerRemember that YES/NO Executive Decision Makerwhich was so popular? In this superior edition, a choiceof eight replies is possible.Program Listing10 DIM D$(8,16)20 RAND100 LET D$(l)=•YESn110 LET D$(2)=•FIRE SOMEONE•120 LET D$(3)= 0 PASS THE BUCKn130 LET D$(4)=•MAYBE 0140 LET D$(5)=•REORGANIZEn150 LET D$(6)=•Non43


160 LET D$(7)=•sEE YOUR ANALYST"170 LET D$(8)=•SIT ON ITn200 LET R=INT(9*RND)210 IR R


160 PRINT S;n SECONDS HAVE ELAPSEDn170 PRINT180 PRINT190 GOTO 1031 Wipeout!Warning: handle with care!Careless operation of this program can cause you a lotof extra work.Key in the program. Run it. When it asks for thepassword, be sure to give it what it wants or it will eraseitself. That's right, the entire contents of program memorydown 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 comparedto the true password. If correct, action goes to line50. If incorrect, the program goes to line 40.The NEW statement in line 40 erases everything fromprogram memory.You can change the password in line 30 to any letters,numbers or keyboard symbols of your choice. Watch outwhen testing. A wrong password can cause a lot of retyping.Program Listing10 PRINT "WHAT IS THE SECRET WORD ?n20 INPUT W$30 IF W$="TRACEYn THEN GOTO 5040 NEW50 PRINT "CORRECTn60 PRINT "THE SECRET WORD IS ";W$45


32 Sentence WriterPractice your English!Exhibit your knowledge of nouns and verbs. Thisprogram leads the computer to solicit individual words fromyou and use those words to create sentences.Besides helping you better understand verbs, nounsand simple declarative sentence structures, the programdemonstrates the computer's ability to simulateconversation and communication.Lines 20, 30 and 40 take in the words. Then action goeson to line 70 where the program pushes the computer backup to line 10. At line 10, everything starts over.You may modify the program to suit your own interestsor needs.Program Listing10 PRINT •A.,._PLURAL NOUN = . ,20 INPUT N$25 PRINT "A VERB = ?•· . ,30 INPUT V$35 PRINT •A SINGULAR NOUN = ?•· . ,40 INPUT S$50 CLS60 PRINT •THE •+N$+• •+v$+" •+s$+"."65 PRINT70 GOTO 10Sample RunA PLURAL NOUN = ?DOGSA VERB = ?LOVEA SINGULAR NOUN = ?FOODTHE DOGS LOVE FOOD.46


A PLURAL NOUN = ?BOXESA VERB = ?HOLDA SINGULAR NOUN = ?WATERTHE BOXES HOLD WATER33 CategorizingA large quantity of numbers can be categorized andthereby cut down into a smaller quantity of numbers. Seeour example: it takes test scores and divides them intoranges labeled A, B, C, D, and F.The program assumes exam or test scores in a rangeof 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 theletter X to stop the entry cycle.Lines 100-140 sort all scores into the A through Fcategories. Lines 150-170 sort highest and lowest scores.Program Listing10 GOSUB 40020 PRINT •scoRE=n30 INPUT G$40 CLS50 IF G$=•x 0 THEN GOTO 20060 LET G=VAL G$70 LET N=N+l100 IF G59 AND G69 AND G79 AND G89 THEN LET A=A+l150 IF N=l THEN LET L=G155 I~ N=l THEN LET H=G47


160 IF GH THEN LET H=G180 GOTO 20200 PRINT •TOTAL •;N;• SCORES"210 PRINT •FROM •;L;• TO •;H220 PRINT •A",A230 PRINT •s",B240 PRINT •c 0 ,C250 PRINT •0 11 ,D260 PRINT •F",F270 STOP400 CLEAR410 LET A=j420 LET B=j430 LET C=j440 LET D=j450 LET F=j460 LET N=j470 RETURN34 Alphabet SoupSure, everybody knows there are 26 letters in thealphabet. 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. Thecomputer will spit out number-and-letter combinations allday long. The number on the left is the position in thealphabet of the letter on the right.It's a fun way to demonstrate to your friends just how"smart" the computer is!How does it work? The alphabet is stored, at line 20.Line 30 generates a random number. Line 40 cuts off anyzeros which are generated. Now the useful random numbersrange from one to 26.Line 60 then uses the current random number, from oneto 26, to pick one letter from the character variable Z $.Line 90 causes action to jump back to line 10 where thewhole process starts over.48


Program Listing10 RAND20 LET Z$=•ABCDEFGHIJKLMNOPQRSTUVWXYZn30 LET P=INT(27*RND}40 IF P


30 PRINT A$;40 GOTO 1036 Question & AnswerHere's how to use the DATA statement, and the computer'sability to.search for data, to create a Q&A.How many days are there in a month? It's a toughquestion for grade schoolers and some extra study may bein order. Use this program.The program has the computer present the numberofa monthandthen askhow manydays are in that particularmonth.If you enter a correct answer, the computer will say so.If you enter an incorrect answer, the computer will sayyour anwer was wrong and tell the correct answer.The program runs on forever until you press theBREAK key,Program Listing10 DIM 0(12)20 RAND100 LET D(l)=31110 LET D(2)=28120 LET D(3)=31130 LET D(4)=30140 LET D(5)=31150 LET D(6)=30160 LET D(7)=31170 LET D(8)=31180 LET D(9)=30190 LET 0(10)=31200 LET 0(11)=30210 LET 0(12)=31300 LET R=INT(l3*RND}310 IF R


410 INPUT D420 CLS430 IF D=D(R} THEN GOTO 600500 PRINT nWRONGn510 GOTO 610600 PRINT nCORRECTn610 PRINT nMONTH "';R;n HAS "';D(R};n DAYS"620 PRINT630 GOTO 1051


Gee Whiz


37 Gee Whiz I: Smart AdderThese six programs, in this section of the book, makeup our Gee Whiz series. One of the fun ways to use yourTIMEX is in wowing your friends. Next time they ask,"But, what can it do?", show them its uncanny abilities atadding, spelling, writing upside down, even crackingjokes. Try these six Gee Whiz programs on your friends.You'll love their reactions.Smart Adder is the first in the series. When yourneighbor drops in for a cup of coffee, bring out the TIMEXfor 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 allnumbers up to and including your number. For instance, ifyou give it a five, it will add 1 plus 2 plus 3 plus 4 plus 5and display the result.Ask your neighbor how fast he or she can add all thenumbers to 100. It should take several minutes. Whilehe's working on it, let your TIMEX do it in a split second.Your neighbor's reaction is bound to be, "Gee whiz!"Program Listing10 LET X=ftf20 PRINT nGIVE ME A NUMBER"30 INPUT N40 FOR L=l TO N50 LET X=X+L60 NEXT L70 PRINT80 PRINT nTHE TOTAL OF 1 TO n;N;n IS n;X90 PRINT100 CLEAR110 GOTO 1055


38 Gee Whiz II:Three-Digit MysteryHave your neighbor secretly select any three-digitnumber in which all three digits are the same. Then havehim tell the computer only the sum of those three digits.The computer will identify his secret number!Program Listing10 CLS20 PRINT •sELECT A THREE-DIGIT NUMBER 030 PRINT •wITH ALL THREE DIGITS THESAME 040 PRINT50 PRINT •ADD THE THREE DIGITS TOGETHER"60 PRINT •WHAT IS THE SUM 065 PRINT •oF THE THREE DIGITS ?n70 INPUT N75 CLS80 LET Q=37*N90 PRINT100 PRINT •yoUR ORIGINAL NUMBER WAS •;Q110 PRINT120 PRINT130 GOTO 2039 Gee Whiz Ill: Yes/NoDecision MakerThis is handy for the busy executive who doesn'thave time for decisions.Line 10 clears the screen. Line 20 generates a randomnumber from zero to 99. Line 30 selects a yesanswer if the random number is greater than 49. Otherwise,line 40 chooses a no answer.56


Program Listing10 CLS20 LET X=lOO*RND30 IF X>49 THEN PRINT 8 YESn40 IF X


41 Gee Whiz V: SecondAlphabet SpotterThis Gee Whiz program has the computer ask you foranother number from 1 to 26 and then, faster than ajackrabbit, tell you what letter it goes with.Program Listing10 CLS20 CLEAR30 LET A$= 0 ABCDEFGHIJKLMNOPQRSTUVWXYZ 040 PRINT "'GIVE ME THE NUMBER OF"'50 PRINT "'A LETTER FROM THE ALPHABET 060 PRINT "'FROM 1 TO 26 1170 INPUT N80 CLS90 PRINT •LETTER NUMBER "';N;"' IS 11;A$(N)100 IF INKEY$=• 0 THEN GOTO 100110 GOTO 1042 Gee Whiz VI: GuessThe NumberHere it is! The world's oldest, longest running, mostpopular game: Guess The Number.When you start the program running, the computerthinks of a number and stores that away. You try to guessthe 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.58


Program Listing10 CLS20 CLEAR30 LET Q$= 0 * 040 GOTO 13050 LET N=INT(lOl*RND)60 PRINT nGUESS THE NUMBERn70 INPUT G80 IF G>N THEN PRINT nTOO HIGH 090 IF G


Number Crunching


43 Memory TesterMost everybody can remember numbers. At least shortnumbers with few digits. But how long a number can yourecall in a flash?The computer will briefly display a number. It then willremove the number from your view and ask you to repeatwhat it was. If you make a mistake in your reply.it won'tshowyou the number again. If you miss three times, the computerwill tell you to FORGET IT, give you your score and end thegame. Then it will start over.On the other hand, if you recall correctly, the computerwill say so and then give you a new number. The newnumber will have more digits than the previous number.Each time you guess correctly, the number gets longer.No matter how good you are, at some point you won'tbe able to recall all the digits in proper sequence.By the way, if you just can't operate at the speed of thisprogram, you can slow down the display by changing thenumber 100 in line 65.How many digits can you quickly recall?Program Listing10 LET W=JJ15 LET R=JJ20 LET Z=l30 LET S=INT(lOO*RND)40 LET N=INT(S*Z)60 PRINT •REMEMBER n;N65 PAUSE 10070 CLS80 IF W=3 THEN PRINT nFORGET ITn85 IF W=3 THEN GOTO 14590 PRINT nWHAT WAS IT ?n95 INPUT S100 IF SN THEN PRINT "WRONG"105 IF SN THEN LET W=W+l110 IF SN THEN GOTO 80115 PRINT "RIGHTn63


120 LET R::R+l125 LET W=j130 LET Z=ll*Z135 PRINT R;n RIGHT SO FARn140 GOTO 30145 PRINT nyou HAD •;R;n RIGHTn150 PRINT •LETS START OVER"155 GOTO 1044 Number Reverser IThis program generates a series of random numbersand then adds them up. Then it reverses the order of thedigits in the total. Creates a very strange random number!Lines 20-40 generate three random single-digitnumbers. Line 50 is a trap to make sure they are between1 and 9 with no zeros showing up.Line 60 changes the number values into strings sothey can be tied together as three digits at line 75'. Line 85takes those three-digit strings from line 75 and turns themback into numerical values.Line 10 5, is a time delay loop to stall a moment beforeline 110 pushes action back up to line 10 for a new start.Program Listing10 CLS20 LET J=INT(lO*RND)30 LET K=INT(lO*RND)40 LET L=INT(lO*RND)50 IF J


100 PRINT •BACKWARD, IT IS •;R105 PAUSE 200110 GOTO 10l45 Number Reverser IIGive the computer a number. It will immediately,display the number printed backward on the videodisplay.Line 20 collects the number from you. Line 30measures its length. Lines 40-70 reverse it and line 80displays the reversed number.Program Listing10 LET B$= 0 •20 PRINT 0 GIVE ME A NUMBER •;25 INPUT N$30 LET L=LEN N$35 PRINT N$40 FOR Y=L TO 1 STEP -150 LET B$=B$+N$(Y)60 NEXT Y70 LET B=VAL B$80 PRINT 0 REVERSED, THE NUMBER IS •;B90 PRINT100 GOTO 1046 Number-Error TrappingGood programs, those which are well written, neederror trapping. It's a technique for making sure personscommunicating with the computer don't key in inappropriatedata or make mistakes which would cause computationproblems for the computer.For instance, see the example program here. In line65


10 the computer asks for a number. In line 20, if thenumber is too low, it says so and goes back to line 10 torepeat its request.'At line 30, if the number received at line 10 is toolarge, it says so and goes back to line 10 for a betterchoice.The result is only printed at line 40 when a satisfactorynumber has been keyed in back at line 10.You can set your own limits by changing the 10 inline 20 and the 100 in line 30.Program Listing10 PRINT •GIVE ME A NUMBER"15 INPUT A20 IF AlOO THEN PRINT ·Too HIGHn35 IF AlOO THEN GOTO 1040 PRINT A;• IS OKAY•50 PRINT60 PRINT70 GOTO 1047 Standard DeviationHere's a way to determine mean and standard deviation.In this particular program, you exit the entry cycle byentering the large number 999999999 (nine 9's) so youcan't use 999999999 as one of your data points.This is a great opportunity to experiment with standarddeviation computations. Try a series of data pointssuch as 3, 5, 3, 7, and 4. They should result in a total of 22;mean of 4.4; variance of 2.24; and standard deviation of1.496663.Program Listing10 GOTO 16020 PRINT •nATA POINT: •;25 INPUT X66


48 PercentagesUsually it's more convenient to enter percentages aspercent rather than having to convert to decimals in yourhead first. Of course, the computer needs that converteddecimal value to do its work. How to get it?This program does the trick. You give it a percentageand it converts that to a decimal. The computer does thehard work for you!Line 30 makes the actual conversion. Use this idea aspart of a larger check-balancing, accounting or bookkeepingprogram and save lots of mental effort. ·67


Program Listing10 PRINT •WHAT IS THE PERCENTAGE ?"20 INPUT P30 LET D=O.Ol*P40 PRINT •THE DECIMAL IS •;n50 PRINT60 CLEAR70 GOTO 1049 Logic FunctionsYou can make your computer do things based on itsdecision that something exists. That is, in the first programlisting here, it only will print the value of C if it findsthat B has an existing value. If Bis found to have no value,does not exist, C will not be printed.The decision is in line 40. The machine only prints Cif 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 ofline 40. If nothing had been stored in B, the last half of line40 would have been ignored.Program Listing10 CLS20 LET B=lO30 LET C=lO*B40 IF B THEN PRINT CIn the second program here, the TIMEX only displaysthe results of the tests in lines 40 and 50 if the results ofone or both is "true."By doing the simple math in your head, you can seethat the information in the right-hand side of line 20 istrue. The information in the right-hand side of line 30 isfalse.Line 20 says that 6 + 8 is greater than 3 times 4. Thatis, 14 is greater than 12. That is true.68


Line 30 says that 5 + 2 is greater than 9 + 2. That is, 7is greater than 11. That is false.After reading line 20, the computer will store a 1 in Bsince the statement is true. Upon reading line 30, thecomputer will store a zero in C since the statement isfalse.As action drops to line 40, the computer will find the1 it stored in B and, thus, complete the action called for atthe 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 thatinstruction. It only will do the right-hand end if it findssomething in the left-hand end.These logic functions are great for quick tests.Program Listing10 CLS20 LET B=(6+8)>(3*4)30 LET C=(5+2)>(9+2)40 IF B THEN PRINT "B OKAY"50 IF C THEN PRINT "C OKAY"50 Above & Below a LineHere's a way to count numbers above and below acut-off line. The computer solicits numbers between 1and 100. Any numbers you key in which are below 1 orabove 100 are trapped out by line 40. Entering a zeroends the input cycle.Line 50 counts the total numbers. Line 60 counts onlythose numbers between 1 and 50. Line 80 counts thenumbers from 51 to 100. Lines 90 to 130 present results.Program Listing10 GOTO 16020 PRINT "GIVE ME A NUMBER ";69


25 INPUT Z30 IF Z=I THEN GOTO 8035 PRINT Z40 IF ZlOO THEN GOTO 2050 LET N=N+l60 IF Z


50 LET M=N/L60 IF M=INT M THEN LET Q(L)=M70 NEXT L80 PRINT nFACTORS ARE:n90 FOR L=l TO N/2100 IF Q(L)>l THEN PRINT Q(L)105 IF Q(L)>l THEN GOTO 120110 LET Z=Z+l120 NEXT L130 IF N=l THEN PRINT nNONEn135 GOTO 145140 IF Z=INT N/2 THEN PRINT nNONEn150 CLS160 LET M=jf170 LET Z=jf180 GOTO 2052 Which is Smallest?How can the computer tell which number is smalleror larger? Here's how.Type in the program and RUN it. It will ask for, and accepta continuous string of numbers until you end the inputroutine by keying in a zero.Lines 40 to 60 make the decision as to which numberis lowest.Press any key to restart .Program Listing10 LET N=jf15 LET D=jf20 PRINT nGIVE ME A NUMBER n ,•25 INPUT Z30 IF Z=jf THEN GOTO 8035 PRINT Z40 LET N=N+l50 IF N=l THEN LET D=Z60 IF Z


70 GOTO 2080 CLS90 PRINT "THE SMALLEST NUMBER WAS •;n100 IF INKEY$=•• THEN GOTO 100110 CLS120 GOTO 1053 Which is Largest?Suppose you have a group of numbers and you wouldlike to know which number is largest within the group?Here's a software routine for your TIMEX so it can locatethe largest number.You can key in as many numbers as you wish. To endthat entry cycle, type in a zero. The computer will see thatzero as its cue to leave the entering routine and get onwith computing.Press any key to restart .Program Listing10 LET N=J15 LET H=J20 PRINT •GIVE ME A NUMBER n ,•25 INPUT Z30 IF Z=J THEN GOTO 8035 PRINT Z40 LET N=N+l50 IF :N=l THEN LET H=Z60 IF Z>H THEN LET H=Z70 GOTO 2080 CLS90 PRINT •THE LARGEST NUMBER: n ;H100 IF INKEY$=•• THEN GOTO 100110 CLS120 GOTO 1072


54 ReciprocalsKey in any number. The computer will display itsreciprocal. The actual conversion is done here at line 30.Program Listing10 LET R=JI20 PRINT •NUMBER TO CONVERT TO RECIPROCAL"25 INPUT N30 LET R=l/N35 CLS40 PRINT •THE RECIPROCAL OF •;N45 PRINT •Is •;R50 PRINT55 GOTO 1055 Dump the IntegerLook at the number 123.456 with an eye toward howto get rid of the portion left of the decimal point. Keeponly .456 and dump 123. Here's a short program tc accomplishthat.Try 5.67. It will come out .67. Or 500.5 which willcome out .5.Caution: your TIMEX is not always accurate at math.Try ,987.65, for example. It will result in .64999986because when the TIMEX subtracts 987 from 987.65 atline 30 it does not get .65 as the correct answer. Rather, itgets an approximate answer!Program Listing10 LET X=JI20 PRINT •GIVE ME ANY NUMBER"30 PRINT •wITH A DECIMAL"40 INPUT N50 LET X=N-INT N73


60 CLS70 PRINT "THE FRACTIONAL PORTION"80 PRINT "OF 0 ;N; 0 IS ";X90 PRINT100 GOTO 1056 AveragesKey in numbers in any order. A zero will end entry.The computer will tell you the average number of allnumbers you entered.Program Listing10 LET N=ftf15 LET T=ftf20 LET A=ftf25 PRINT "GIVE ME A NUMBER0;30 INPUT Z35 IF Z=ftf THEN GOTO 7040 PRINT Z45 LET N=N+l50 LET T=T+Z60 GOTO 2570 LET A=T/N80 CLS90 PRINT 0 THE AVERAGE NUMBER IS 0 ;A100 PRINT110 GOTO 1057 Mid-Range NumberHere's how to find the middle of a range of numbers.You key in as many numbers in a series as you wish. Afterthe last number, key in a zero to move the program out ofthe entry cycle.74


Lines 40 to 70 select the highest and lowest numbersin the range. They actually define the range. Then line 90finds the middle point of that range.Program Listing10 LET N=frf15 LET M=frf20 LET H=frf25 LET L=frf30 PRINT nGIVE .ME A NUMBER n;35 INPUT Z40 IF Z=frf THN GOTO 9045 PRINT Z50 LET N=N+l55 IF N=l THEN LET H=Z60 IF N=l THEN LET L=Z65 IF ZH THEN LET H=Z80 GOTO 3090 LET M=L+((H-L)/2)100 CLS110 PRINT nTHE MID-RANGE NUMBER IS n;M120 PRINT130 GOTO 1058 Rounding OffThe technique for rounding off numbers is easy.This program, which can stand alone or be worked into alarger program as a subroutine, rounds a decimal to thenearest whole number.Program Listing10 LET R=frf15 LET D=frf20 PRINT nGIVE .ME A NUMBERn25 PRINT nTO BE ROUNDED OFF"·75


30 INPUT N35 IF N>INT N THEN GOTO 5040 LET R=N45 GOTO 10050 LET D=N-INT N60 IF D>0.5 THEN GOTO 9070 LET R=INT N80 GOTO 10090 LET R=(INT N)+l100 CLS110 PRINT N;" ROUNDS OFF TO ";R120 PRINT130 GOTO 1059 Two-Digit Round OffIt is possible to round off to the nearest hundredthsplace. That is, to two digits after the decimal point. Here'show:Program Listing10 LET R=Jf20 PRINT "GIVE ME A NUMBER TO"30 PRINT "MORE THAN TWO DECIMAL PLACES"40 PRINT50 PRINT "ORIGINAL NUMBER"60 INPUT N70 LET R=INT(lOO*N+0.05)/10080 CLS90 PRINT N;" ROUNDS OFF TO ";R100 PRINT110 GOTO 1076


60 Percent to DecimalChecking, interest, sales tax, and other financial programsare more "user friendly" if you don't have to makemanual conversions in your head. For example, if youknow your savings account earns 8 percent interest, andyou 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 theTIMEX figure out the decimal value.Here's another way to change percentages to decimalsinside a program to simplify entry by permittingpercents to be entered as simple numbers.For some examples, try entering a price of 2.50 and asales tax percentage of 6. Your TIMEX will find the billtotals $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 Listing10 LET T=ftf20 LET B=ftf30 PRINT •PRICE: $•;40 INPUT P50 PRINT P60 PRINT 0 SALES TAX RATE: •;70 INPUT R80 PRINT R; 0 PERCENT•90 LET T=O.Ol*R100 LET B=P+T*R110 PRINT •BILL TOTALS: $•;B61 Every 10th AnswerThis program generates a random number in therange of zero to 999. However, it has a difference. It onlyshows you every tenth number it generates.77


Line 20 generates the numbers. Line 40 selects thetenth number from each set.Program Listing10 LET T=J15 LET V=J20 LET T=INT(lOOO*RND)30 LET V=V+l40 IF (V/lO)=INT(V/10) THEN PRINT V,T50 GOTO 2062 Random SamplerThis program strengthens your confidence in the ran•dom number generator built into your TIMEX computer.It generates 100 numbers between zero and 100 andtells you how many of those are above 49 and how manyare below 50. See the sample RUN for several sets ofresults in our recent test.Program Listing10 LET N=Jj15 LET X=J20 LET Y=J25 FOR L=l TO 10030 LET X=INT(lOO*RND)35 IF X49 THEN LET N=N+l45 NEXT L50 PRINTY;• YES"55 PRINT N;" NO"60 PRINT65 GOTO 1078


Sample Run51 YES 4649 NO 54YESNO42 YES 5258 NO 48YESNO56 YES 4844 NO 52YESNO63 Random Numbers:Zero To NineAlthough you see four program lines below, wnat wereally have here is a very convenient single-line programfor you to insert in a larger game or educational-testingprogram.Line 20 is the winner here. It prints a random numberfrom zero to nine every time. For your use here, we printthat number on the screen. You could just as easily havethe computer store that random number in a memorylocation for later recall and use.We have added lines 10, 30 and 40 to make yourTIMEX show you a whole series of random numbers fromzero to nine. Remember, line 20 is the important singlelineprogram element here.If you would like random numbers in the range fromzero to 99, make it 100* in line 20. For zero to 999, use1000* in line 20.Program Listing10 RAND20 PRINT INT (lO*RND)30 PAUSE 10040 GOTO 2079


Random Numbers:Distr~butionEver wonder how "random" are the numbersgenerated the random-number generator in yourTIMEX when you use the RND instruction? Try this program.It generates 100 random numbers in a range fromzero to four and counts how many there are of eachnumber between zero and four.By the way, while it is doing that it will display themessage "counting" so you can tell it is worl


Sample RunCOUNTING0: 8l: l 02: 143: 164: 6COUNTING0: 6l: 122: 113 : l 34: 765 Random Numbers:AveragesThis program generates 100 random numbers andtotals them. Then it finds the average of all 100 numbers.In fact, the average number itself is a useful new randomnumber.Program Listing10 LET A=fl20 LET N=fl30 LET T=fl40 FOR L=l TO 10050 PRINT nAVERAGING"60 LET N=INT(lO*RND)70 LET T=T+N80 CLS90 NEXT L100 LET A=T/10081


110 PRINT "RANDOM NUMBERS TOTAL ";T120 PRINT "AVERAGE NUMBER IS ";ASample RunAVERAGINGRANDOM NUMBERS TOTAL 444AVERAGE NUMBER IS 4.44AVERAGINGRANDOM NUMBERS TOT AL 424AVERAGE NUMBER IS 4.2466 Random Numbers:Sorting High/LowIt's important to be able to sort a group of numbers tosee what the highest and lowest values are. This programdoes that.The random number generator is in line 30. It givesnumbers in a range of zero to 999. Line 50 determines thelowest number in the set and line 60 finds the highestnumber.Program Listing10 LET H=g15 LET L=g20 LET N=g25 FOR A=l TO 10030 LET N=INT(lOOO*RND)35 IF A=l THEN LET L=N40 IF A=l THEN LET H=N45 PRINT "SORTING"50 IF NB THEN LET H=N70 CLS82


80 NEXT A90 PRINT ·Low NUMBER IS •;L100 PRINT •eIGH NUMBER IS •;uSample RunSORTINGLOW NUMBER IS 32HIGH NUMBER IS 983LOW NUMBER IS 14HIGH NUMBER IS 980LOW NUMBER IS 17HIGH NUMBER IS 985LOW NUMBER IS 9HIGH NUMBER IS 991LOW NUMBER IS lHIGH NUMBER IS 99483


Money Matters


67 Money GrowsThis section of the book includes a number of programsrelating to household money management and tosmall-business applications. This first program showsyou how your money grows when deposited in a savingsaccount at a certain annual interest rate, compoundedmonthly.The program will have the computer ask for the initialamount of principal saved by depositing in the account.Then the annual interest rate and the number of monthsto be displayed. The result of the run is a display of thechanging principal as months pass and interest is addedon.Program Listing10 LET I=Jf20 PRINT nPRINCIPAL = $n;30 INPUT P40 PRINT P50 PRINT nANNUAL INTEREST RATE = n ,•60 INPUT R70 PRINT Rn.80 PRINT nNUMBER OF MONTHS ,90 INPUT M100 PRINT M110 FOR Q=l TO M120 LET I=(P*(O.Ol*R))/12130 LET P=P+I140 PRINT Q;n MONTH= $";P150 NEXT Q160 PRINT170 IF INKEY$=n" THEN GOTO 170180 CLS190 GOTO 1086


Shopper's FriendTake your computer along the next time you goshopping!This program finds the computer asking for certaininformation and then telling you which product brand nameis the best buy.The computer wil ask for the brand name of a product,the quantity in the product package, and the price of thepackage. Then it will ask for the name, quantity and pricefor a second product.After digesting all this information, it will tell you thebrand name of the best-buy product and show you the unitprices for both brand names so you can agree with thecomputer's judgment.For example, suppose you were looking at corn flakesin boxes, one by Post and one by Kellogg. Suppose the Posi:box contained 24 ounces of flakes and was priced on thegrocery shelf at $1.98 while the Kellogg box held 18 ouncesand was priced at $1.59. Which would be the better buybased on unit price per ounce of flakes?Run the data through your TIMEX and you'll find itcomputes the Post corn flakes to be the best buy with a unitprice of 8¢ vs. the Kellogg unit price of 9¢.After completing the computation, the computer asksfor a yes or no answer. Do you have more to be computed?By the way, if the unit prices turn out to be equal, thecomputer will say they are equal. If you want no furthercomputations, it will say thanks and quit.10 PRINT ~SHOPPERS FRIEND~20 FOR L=l TO 1530 PRINT '"*"";40 JN!EXT L50 PRINT100 PRINT ~FIRST BRAND NAME:~110 INPUT X$120 PRINT X$130 PRINT ~QUANTITY~ ~~87


140 INPUT M150 PRINT M160 PRINT nPRICE: $n;170 INPUT N180 PRINT N200 PRINT nsECOND BRAND NAME: n210 INPUT Y$220 PRINT Y$230 PRINT nQUANTITY: .. ,240 INPUT Q250 PRINT Q260 PRINT nPRICE: n. ,270 INPUT R280 PRINT R300 IF N/M=R/Q THEN GOTO 600310 IF N/M


POST IS BEST BUYPOST UNIT=$0.08KELLOGS UNIT=$0.09FIRST BRAND NAME ?BLACKSQUANTITY ?100PRICE ?25SECOND BRAND NAME ?WHITESQUANTITY ?50PRICE ?12.5BLACKS = WHITESBLACKS UNIT=$0.25WHITES UNIT=$0.2569 Car PaymentsShopping for a new car? Use your TIMEXComputerto compute quickly the potential monthly car paymenton various models.Imagine you want an $8000 car and are prepared to putup $1000 against the purchase. You want to arrange tofinance the car for 36 months. You know the current annualinterest rate on car loans is 15 percent.Key in those few numbers and the computer instantlytells you the car payment will be $242.66 per month.Program Listing10 LET P=fl20 PRINT •cAR PAYMENT•30 FOR L=l TO 1140 PRINT n*n;89


50 NEXT L60 PRINT100 PRINT "PURCHASE PRICE ?"110 INPUT T120 CLS130 PRINT "DOWN PAYMENT ?"140 INPUT R150 CLS160 PRINT "NUMBER OF MONTHS ?"170 INPUT N180 CLS190 PRINT "ANNUAL INTEREST ?n200 INPUT I210 LET I=(O.Ol*I)/12220 CLS230 LET P=(T-R)*I/(1-1/(l+I)**N)240 LET P=INT(lOO*P+.5)/100250 PRINT •PAYMENT WILL BE"260 PRINT "$";P;" A MONTH"Sample Run**************CAR PAYMENTPURCHASE PRICE $ ?8000DOWN PAYMENT $ ?1000NUMBER OF MONTHS ?36MONTHLY INTEREST ?15/12PAYMENT: $ 242.669070 To Nearest 95 CentsMany companies like to price their goods at a figure


ending in 95 cents. For instance, a ten dollar item mightbe marked $9.95 or $10.95.Here's a program which demonstrates how to makeall prices come out to the nearest 95 cents. See line 40. Itmerely takes the integer portion of the dollars numberand adds 0.95 to it.Program Usting10 LET P=g20 PRINT •MANUFACTURING COST:"25 INPUT C30 PRINT "PRICING MULTIPLIER:•35 INPUT M40 LET P=INT (C*M)+0.9550 CLS60 PRINT •RETAIL PRICE: $";P70 PRINT80 GOTO 1071 To the Nearest PennyThis program is useful when you have a dollar-andcentsfigure with more than two decimal places. For example,$151.6972. You need to transform $151.6972 to themore common $151.70This small program would make a good subroutine ina larger set of instructions. To do so, insert GOSUB at theappropriate place in the larger set of program lines.Modify the line numbers of this small program so thesubroutine will be located in an unused position in thelarger listing. Change the last line of this small program toRETURN.Program Listing10 LET R=g20 PRINT •ENTER A NUMBER TO"30 PRINT "MORE THAN TWO DECIMAL PLACES"91


40 PRINT·"ORIGINAL AMOUNT$= n50 INPUT N60 LET R=INT(lOO*N+.5)/10070 CLS80 PRINT "TO THE NEAREST PENNY"90 PRINT "$";N;" IS $";R100 PRINT110 GOTO 1072 Mark UpMr. Storekeeper, here's just what you have needed tocompute mark ups. This program causes your TIMEX tofind the retail price for which your percentage off wouldgive the wholesale cost.For instance, if you got 40 percent off on an item andpaid $60, how much was it priced at, at retail? The answeris $100. To put that another way, if retail prica or suggestedretail price is $100 and you got 40 percent off atwholesale, what is the wholesale price? The answer is$60.Try $40 wholesale which is 60 percent off. Theanswer is $100 retail. Or try $10 wholesale at 90 percentoff. Retail would be $100. Or $75 wholesale at 25 percentoff gives $100 retail.Here's a toughie! Try $19.95 wholesale cost. Mark-uppercentage is 40. The correct retail answer is $33.25.Program Listing10 LET D=f,J20 LET R=f,J30 PRINT"WHOLESALE COST = $II;40 INPUT W50 PRINT wn •60 PRINT "MARK-UP PERCENTAGE = ,70 INPUT p80 PRINT p90 CLS92


100 LET D=l-0.0l*P110 LET R=W/D120 PRINT •RETAIL PRICE = $•;R130 PRINT140 GOTO 1073 Percentage OffFrom earlier tips in this book, you know how to makeyour TIMEX convert percentages to decimals. But what ifyou want to know "percentage off?"For example, how much is 40 percent off? This programcan be used to interpret 40 percent off and computethe decimal value needed. Try 40 percent off $100. Thecomputer will change 40 percent off into decimal value0.60. If you multiply 0.60 times $100 you find $60 is 40 percentoff $100.Line 30 makes the important translation.Program Listing10 PRINT •PERCENTAGE OFF:n ,•20 INPUT p30 PRINT p40 PRINT •nECIMAL: •;(1-0.0l*P)50 PRINT60 GOTO 1074 Dollars & CentsIf the result of your computation is a "money"answer, and you don't know whether to display it indollars or cents, let the computer decide.This program decides whether to display the outputin dollars or cents. Line 90 in the program makes thedecision.93


Program Listing10 LET T=Jfn.20 PRINT •QUANTITY = ,30 INPUT p40 PRINT p50 PRINT •TOTAL COST = $";60 INPUT c70 PRINT C80 LET T=C/P90 IF T40 THEN LET T=H-4094


100 IF H>40 THEN GOTO 140110 LET W=H*P120 PRINT nGROSS WAGES = $n;W130 STOP140 LET W=(40*P}+(T*P*l.5)150 GOTO 120Sample RunHOURLY PAY RATE = $5.75NUMBER HOURS WORKED =61GROSS WAGES = $411.12576 InvoicingThere's a lot of repetitious math work to be done beforeyou mail invoices to your customers. This software hasthe computer collect a few pertinent bits of data from youand then present all the various totals you need to plug intoan invoice.It gives you a total retail price for all goods sold on theinvoice, total sales tax if applicable, shipping charges andthe grand total amount due you from your customer.Program Listing10 PRINT nQUANTITY SOLD: n;20 INPUT Q30 PRINT Q40 PRINT nUNIT PRICE: $n;50 INPUT P60 PRINT P70 PRINT nSALES TAX RATE PERCENT: ";80 INPUT S90 PRINT S100 PRINT nSHIPPING CHARGES: $";95


110 INPUT H120 PRINT H130 LET S=O.Ol*S140 LET C=Q*P150 LET T=C*S160 LET F=C+T+H170 LET A=INT(lOO*C+.5)/100180 LET B=INT(lOO*T+.5)/100190 LET D=INT(lOO*F+.5)/100200 CLS210 PRINT nTOTAL PRICE= $n;A220 PRINT nSALES TAX= $n;B230 PRINT nsHIPPING CHARGES = $n;H240 PRINT250 PRINT nINVOICE TOTAL= $n;D260 IF INKEY$=•• THEN GOTO 260270 CLS280 GOTO 10Sample RunQUANTITY SOLDl 78UNIT PRICE = $55.98SALES TAX RATE PERCENT =6SHIPPING CHARGES = $100TOTAL PRICE = $9964.44SALES TAX = $597.87SHIPPING CHARGES = $100INVOICE TOTAL = $10662.3177 Unit PriceSuppose you find 895 green Widgets and buy themfor $695. How much did each green Widget cost?Rounded off, $7.77.96


Unit price is total price divided by quantity. The quantitycan be expressed in weight, total numbers, etc. It worksthe 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, quantitypurchased and total price paid. It then displays quantity,name, total and unit price.Program Listing10 LET U=J620 PRINT nITEM NAME IS n;30 INPUT N$40 PRINT N$50 PRINT nQUANTITY OF ITEMS = n;60 INPUT Q70 PRINT Q80 PRINT nTOTAL PRICE PAID FOR ITEMS=$";90 INPUT P100 PRINT P110 LET U=P/Q120 PRINT N$;n UNIT PRICE = $";USample RunITEM NAME ISWIDGETSQUANTITY OF ITEMS =999TOTAL PRICE PAID FOR ITEMS = $14653BEEP WIDGETS UNIT PRICE = $14.66766878 Bubble SortHere's a handy routine, accepting lists of up to 10names and sorting them into alphabetical order. The sizeof the list is controlled by the DIM instruction in line 20.You can change it.97


Note that 'the screen goes blank while sorting is goingon inside your TIMEX so you must be patient. Themore names to sort, the longer it takes.Of course, you can change names to other categoriessuch as items, products, units, etc.Program Listing10 CLS20 DIM M${10,10)30 FOR L=l TO 1040 PRINT "NAME: •;50 INPUT M${L)60 PRINT M${L)70 NEXT L80 CLS90 LET T=J100 FOR L=l TO 9110 IF M${L)


The computer generates a table of randomly-selectedcodes for seven days at a time.Program Listing10 GO SUB 300100 PRINT ·suNDAY: II ;C110 GOSUB 300120 PRINT •MONDAY: n ;C130 GOSUB 300140 PRINT •TUESDAY: n ;C150 GOSUB 300160 PRINT •WEDNESDAY: n ;C170 GOSUB 300180 PRINT •THURSDAY: n ;C190 GOSUB 300200 PRINT •FRIDAY: n ;C210 GOSUB 300220 PRINT •sATURDAY: n ;C230 STOP300 LET C=INT(lOOOO*RND)310 IF C


Graphics


80 Screen FullFill your video screen with square dots, startingfrom the upper left, moving down and across to the lowerright. Line 200 is a freeze frame.Program Listing10 CLS100 FOR X=l TO 21 STEP 2110 FOR Y=l TO 21 STEP 2120 PRINT AT X,Y;CHR$ 128130 NEXT Y140 NEXT X200 GOTO 20081 Sine WaveNote that some complex screen art can be createdwith only a few program lines. You will want to refinethese programs to make them even shorter.Program Listing10 CLS20 FOR X=l TO 6330 LET Y=SIN X + 1040 PLOT X,Y50 NEXT X60 GOTO 6082 Hold That PoseThe illusion of motion is important in computergraphics. But, to make a character move, you have to drawit first!Here we have created a friendly little stick man. But,103


having created him on the graphics screen, how can wekeep him there? By using a freeze frame as we have donehere in line 300.Line 300 is an endless loop, holding action at line 300forever, until you press the break key.Run this program first. Then, go on to Tip Number 83.Program Listing10 CLS20 FOR X=20 TO 3030 PLOT X,3540 NEXT X50 FOR Y=35 TO 25 STEP -160 PLOT 30,Y70 NEXT Y80 FOR X=30 TO 20 STEP -190 PLOT X,25100 NEXT X110 FOR Y=25 TO 35120 PLOT 20,Y130 NEXT y140 PLOT 22,33150 PLOT 28,33160 PLOT 25,30170 FOR X=22 TO 28180 PLOT X,27190 NEXT X200 FOR Y=25 TO 5 STEP -1210 PLOT 25,Y220 NEXT Y230 FOR X=20 TO 30240 PLOT X,5250 NEXT x300 GOTO 30083 Okay, Now WaveThis is a development of the stick man drawn andfrozen on the screen in Tip Number 82. Here, we add pro-104


gram lines to draw and seem to move the stick man's leftarm on the right side of the TV screen. The result is theappearance of arm motion. Very clever, these stick men!Program Listing10 CLS20 FOR X=20 TO 3030 FOR Y=S TO 35 STEP 1040 PLOT XrY50 NEXT Y60 NEXT X70 FOR Y=25 TO 3580 FOR X=20 TO 30 STEP 1090 PLOT XrY100 NEXT X110 NEXT Y120 PLOT 22r33130 PLOT 28r33140 PLOT 25r30150 FOR X=22 TO 28160 PLOT Xr27170 NEXT X180 FOR Y=S TO 25190 PLOT 25rY200 NEXT Y210 FOR X=30 TO 26 STEP -1220 UNPLOT Xrl5230 NEXT X240 PAUSE 60250 FOR X=26 TO 30260 PLOT Xrl5270 NEXT X280 PAUSE 60290 GOTO 21084 Create A TableThis program generates a table of values, as a105


demonstration on how to set up a table on the videodisplay.Subroutine lines 900 and 910 generate randomnumbers in the range of zero to 99. Lines 60 and 70 findhow many times through the random number generator ittakes to get a number greater than 50. The answer isstored in A.Lines 90and 100 do it again and store the answer inB.Line 40 prints the table heading and line 110 displaysthe results.Program Listing5 RAND10 LET A='120 LET B='130 LET T='140 PRINT CHR$ 166,CBR$ 16750 GOSUB 90060 IF X>50 THEN LET A=A+l70 IF X>50 THEN GOTO 5080 GOSUB 90090 IF X>SO THEN LET B=B+l100 IF X>50 THEN GOTO 80110 PRINT A,B120 IF T=lO THEN STOP130 LET A='1140 LET B='1150 LET T=T+l160 GOTO 20900 LET X=INT(lOO*RND)910 RETURN85 Go To BlackThere are ways to black-out your screen without goingto the graphics mode. Line 150 is a freeze-frame.106


Program Listing10 CLS100 FOR L=g TO 21110 FOR C=g TO 31120 PRINT AT L,C:CHR$ 128130 NEXT c140 NEXT L150 GOTO 15086 Centered MessageThink up a message of up to 20 characters andspaces. Type it into your TIMEX in response to the requesthere at line 110.The computer will highlight your message by centeringit on the video screen.Use this handy centering program for titles and otherimportant parts of longer programs. It makes a goodsubroutine.Program Listing10 LET A$=nn100 PRINT nMESSAGE:"110 INPUT M$200 LET L=LEN M$210 LET T=L+4220 FOR Z=l TO T230 LET A$=A$+n*n240 NEXT Z250 LET P=(40-T)/2260 CLS300 PRINT TAB P:A$310 PRINT TAB P:n* n:M$:n *n320 PRINT TAB P:A$107


87 Beautiful Braided RugJust goes to show that some of the most attractivecomputer graphics require some of the shortest programs.Program Listing10 FOR X=l TO 20 STEP 220 FOR Y=l TO 20 STEP 230 PRINT AT X,Y;CHR$ 840 PRINT AT X+l,Y+l;CHR$ 12850 NEXT Y60 NEXT X88 Circling DotMore round graphics on your rectangular picturetube.Program Listing10 CLS20 FOR N=l TO 1230 LET X=20-(10*COS(N/6*PI))40 LET Y=l0+(10*SIN(N/6*PI))50 PLOT X,Y60 NEXT N70 GOTO 2089 Making Things MoveMovement on the computer display screen is an illusion.As in any television picture, the turning on and turningoff of dots in a pattern across a screen can seem toprovide motion to an object drawn on the face of the tube.108


There are a number of ways to get the look of motion.Let's send a dot across the screen:Program Listing10 FOR X=jJ TO 6320 PLOT X,20+SIN X30 UNPLOT X-l,20+SIN(X-l)40 NEXT X50 FOR X=62 TO jJ STEP -160 PLOT X,20+SIN X70 UNPLOT X+l,20+SIN(X+l)80 NEXT X90 GOTO 1090 Window TwinklersWell, what would you call them?Program Listing10 CLS20 RAND100 LET X=INT(63*RND)110 LET Y=INT(43*RND)120 PLOT X,Y130 GOTO 10091 Eyeball ScramblerBlink. Blink. Blink. It's enough to make your eyeballshurt!The screen is filled with all the many printablekeyboard characters. Some flash on and off. Some do not.Creates a very lively display!109


Program Listing10 LET X=INT(30*RND)20 LET Y=INT(20*RND)30 LET C=INT(256*RND)40 PRINT AT Y,X;CHR$ C50 GOTO 1092 Flashing DotWant a blinking dot in the upper left-hand corner ofthe screen? You've got it!This program clears the screen and causes that dotto blink. Timing loops in lines 20 and 40 control the lengthof time the dot is on and off.See ASCII number list for other characters to displayas a dot. We use 128.Program Listing10 CLS20 PAUSE 2030 PRINT AT O,O;CHR$ 12840 PAUSE 4050 GOTO 1093 SnowfallWhite flakes sprinkle down the screen, over andover-until you press the BREAK key. It may be uselessbut it's a lot of fun to watch!Program Listing100 FOR X=S TO 63110 FOR Y=lO TO 43120 PLOT X,Y130 NEXT Y110


140 NEXT X200 LET X=INT(63*RND}210 LET Y=INT(43*RND}220 IF Y


130 NEXT X140 NEXT Y200 FOR X=g TO 63 STEP 63210 FOR Y=lO TO 43220 PLOT X,Y230 NEXT Y240 NEXT X300 GOTO 30096 Painting ExercisesJust goes to show that some of the most attractivecomputer graphics require some of the shortest programs.Program Listing10 CLS20 RAND100 LET W=INT(63*RND}110 LET X=INT(63*RND}120 LET Y=INT(43*RND}130 LET Z=INT(43*RND}140 FOR L=W TO X150 FOR K=Y TO Z160 PLOT L,K170 NEXT K180 NEXT L200 GOTO 10097 Draw A LineThere are different ways to draw a line on theComputer screen.112


Program Listing10 LET A$=• 1120 FOR L=l TO 3030 LET A$=A$+"*n40 NEXT L50 PRINT A$Program Listing10 FOR L=l TO 3020 PRINT CHR$ 12830 NEXT LProgram Listing10 FOR X=l TO 5020 PLOT X,1030 NEXT XProgram Listing10 FOR Y=l TO 2520 PLOT 20,Y30 NEXT Y98 Box MessageLet's use low-resolution drawing abilities to create· a box on the video display. First, type in this programto create a box. Again, we've added a never-endingloop at line 500 to freeze the picture. Press the BREAKkey to end the run.Program Listing10 FOR X=8 TO 1720 PLOT X,230 NEXT X113


40 FOR Y~3 TO 950 PLOT 17,Y60 NEXT Y70 FOR X=3 TO 12 STEP 980 FOR Y=8 TO 1390 PLOT X,Y100 NEXT y110 NEXT x120 PLOT 7,3130 PLOT 16,3140 PLOT 6,4150 PLOT 15,4160 PLOT 5,5170 PLOT 14,5180 PLOT 4,6190 PLOT 13,6200 FOR X=3 TO 12210 PLOT x, 7220 NEXT x230 PLOT 16,10240 PLOT 15,11250 PLOT 14,12260 PLOT 13,13270 FOR X=3 TO 12280 PLOT X,14290 NEXT X300 PRINT AT 17,3;nBOX"500 GOTO 50099 Boxed TitleHere's a neat, different way to place a box around aprogram title-or anything else you might like tohighlight.Line 310 is a freeze- frame loop, used here so youcan review your handywork.Program Listing10 CLS114


100 FOR Y=l5 TO 25 STEP <strong>101</strong>10 FOR X=l5 TO 37120 PLOT X,Y130 NEXT X140 NEXT Y200 FOR X=l5 TO 37 STEP 22210 FOR Y=l5 TO 25220 PLOT X,Y230 NEXT Y240 NEXT X300 PRINT AT 11,ll;"TITLE"310 GOTO 3<strong>101</strong>00 Draw Bar GraphsDrawing graphs on the video screen are a popularform of communication today. This program establishes abar graph on the TIMEX display.We have selected the business-like example, shownhere, to demonstrate how you go about setting up a bargraph on the TV screen.Lines 10 to 80 are used to input data needed to begraphed. We have selected annual profits as the subjectfor our graph.Line 10 asks for total profits in the year 1979; line 40for 1980; etc. For the purposes of our graph, the maximumvalue you can enter will be 26. When the computer asksfor the annual-profits data, give it numbers from 1 to 216.Line 110 prints the heading.Lines 200 to 240 create the first-year bar on the graph.Lines 300 to 340 create the second-year bar, and so onthrough line 440 which concludes the last-year bar on thegraph.Program Listing10 PRINT "1979 PROFITS"20 INPUT A30 CLS40 PRINT "1980 PROFITS"115


50 INPUT B60 CLS70 PRINT 0 1981 PROFITS"80 INPUT c90 CLS100 LET X$= 0 "110 PRINT TAB 9;"PROFITS"200 PRINT AT 3,Sf;"l979 n ,•210 FOR L=l TO A220 LET X$=X$+CHR$ 128230 NEXT L240 PRINT X$250 LET X$= 0 "300 PRINT AT 5,Sf; 0 1980 ,II •310 FOR L=l TO B320 LET X$=X$+CHR$ 128330 NEXT L340 PRINT X$350 LET X$=• 11400 PRINT AT 7,SJ;•l981 n ,•410 FOR L=l TO C420 LET X$=X$+CHR$ 128430 NEXT L440 PRINT X$Sample RunPROFITS1979 -19801981116


<strong>101</strong> Random Bar GraphIf you don't have any particular data to display, butwould like to see how these bar graphs work, try thisprogram.It uses a random number generator in line 400 toprovide data.Program Listing10 RAND20 LET X$=""30 PRINT TAB 9;"PROFITS"40 PRINT AT 3,j;"l978 ";50 GOSUB 40060 PRINT AT 5,j;•1979 ";70 GOSUB 40080 PRINT AT 7,j;"l980 ";90 GOSUB 400100 STOP400 FOR L=l TO INT(27*RND)410 LET X$=X$+CHR$ 128420 NEXT L430 PRINT X$440 LET X$=• 11450 RETURN117


Appendix


Appendix A:Sinclair BASIC WordsHere is a convenient list, with short explanations, of eachof the BASIC language words as used by Sinclair in theZX-81 and in the TIMEX/Sinclair 1000 computer:121


FunctionsABS absolute value of a numberACS arccosineAND logical ANDASN arcsineATN arctangentCHR$ changes 0 to 255 number to a characterCODE number of first character in a stringcos cosineEXP exponentINKEY$ scans keyboardINT integer part of numberLEN length of a stringLN natural logarithmNOT logical NOTOR logical ORPEEK look at one memory-address locationPl 3.14159265RND random-number generatorSGN sign of a numberSIN sineSOR square rootSTR$ change numerical value to stringTAN tangentUSR call machine-language routineVAL change string to number+ addition of number or stringssubtraction* multiplicationdivision** raising to a power= equals> greater than< less than>= less than or equal to


StatementsCLEARCLSCONTCOPYDIMDIM $FASTFORGOSUBGOTOIFINPUTLETLISTLUSTLOADLPRINTNEWNEXTPAUSEPLOTPOKEPRINTRANDREMRETURNRUNSAVESCROLLSLOWSTEPSTOPTABTHENTOUN PLOTclears variablesclears screencontinue after STOPcopy TV screen on printerdimensions numerical arraydimensions string arraystarts fast mode of TV displayfirst part of FOR/NEXT loopjump to subroutinejump to a linefirst part of IF/THEN decision makerstops so data can be enteredassigns a value to a variabledisplays program list on TV screendisplays program list on printertransfers program from tape into computerPRINT on printererases all of program memory and variableslast part of FOR/NEXT loopholds TV display on for brief delayblacks in a graphics-screen dotwrites in one memory-address locationdisplays on TV screenreseeds random-number generatorstatement ignored during runend of GOSUB, jump back to main routineclears variables and starts program actionrecords program from computer onto taperolls TV display up a lineswitches to slower display modeoptional part of FOR/NEXT looptemporary halt in a runPRINT at a certain place on TV displaylast part of IF/TH EN decision makerfollows FOR in FOR/NEXT loopblanks out a graphics-screen dot123


Appendix B: Error MessagesThis is a list of what Sinclair calls Report Codes and whatyou may refer to as error messages. These are notes toyou from the computer about mistakes you may havemade and about the status of the computer:CodeNumber/Letter0123456789ABcDFDescriptionof Erroror Statussuccessful completionyou have a NEXT without a matching FORyou forgot to use LET or DIM or your FORvariable wronga subscript is wrongthere's not enough memory space for whatyou want to dothe TV screen is fullyou have computed too large a numberyou have a RETURN without a matchingGOSUBINPUT can only be used in a program lineCONT can't restart at STOPyou are not using the function correctlyan integer is out of rangeyou can't VAL that stringyou used BREAK to interrupt a run or you areusing STOP in an INPUT linethere is no such program name125


ooks from ARCsoft PublishersFor 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 <strong>page</strong>s $7.95 ISBN 0-86668-019-5<strong>101</strong> Pocket Computer Programming Tips & Tricks128 <strong>page</strong>s $7.95 ISBN 0-86668-004-7Pocket Computer Programming Made Easy128 <strong>page</strong>s $8.95 ISBN 0-86668-009-8Murder In The Mansion and Other Computer Adventures96 <strong>page</strong>s $6.95 ISBN-0-86668-501-450 Programs in BASIC for Home, School & Office96 <strong>page</strong>s $9.95 ISBN 0-86668-502-250 MORE Programs in BASIC for Home, School & Office96 <strong>page</strong>s $9.95 ISBN 0-86668-003-9Pocket-BASIC Coding Form <strong>programming</strong> worksheet tablets40-sheet pad $2.95 ISBN 0-86668-801-3For the TRS-80 Color Computer:<strong>101</strong> Color Computer Programming Tips & Tricks128 <strong>page</strong>s $7.95 ISBN 0-86668-007-155 Color Computer Programs for Home, School & Office128 <strong>page</strong>s $9.95 ISBN 0-86668-005-555 MORE Color Computer Programs for Home, School & Office112 <strong>page</strong>s $9.95 ISBN 0-86668-008-XColor Computer Graphics128 <strong>page</strong>s $9.95The Color Computer Songbook96 <strong>page</strong>s $7.95My Buttons Are Blue and Other Love Poems96 <strong>page</strong>s $4.95ISBN 0-86668-012-8ISBN 0-86668-011-XISBN 0-86668-013-6Color Computer BASIC Coding Form program worksheet tablets40-sheet pad $2.95 ISBN 0-86668-802-1For the APPLE Computer:<strong>101</strong> APPLE Computer Programming Tips & Tricks128 <strong>page</strong>s $8.95 ISBN 0-86668-015-233 New APPLE Computer Programs for Home, School & Office96 <strong>page</strong>s $8.95 ISBN 0-86668-016-0APPLE Computer BASIC Coding Form program worksheet tablets40-sheet pad $2.95 ISBN 0-86668-803-XFor the ATARI 400 and 800 computers:<strong>101</strong> ATARI Computer Programming Tips & Tricks128 <strong>page</strong>s $8.95 ISBN 0-86668-022-531 New ATARI Computer Programs for Home, School & Office96 <strong>page</strong>s $8.95 ISBN 0-86668-018-7ATARI Computer BASIC Coding Form program worksheet tablets40-sheet pad $2.95 ·ISBN 0-86668-806-4127


ooks from ARCsoft PublishersFor the Sinclair ZX-81 and TIMEX/Sinclair 1000 computers:<strong>101</strong> TIMEX 1000 and Sinclair ZX-81 Programming Tips & Tricks128 <strong>page</strong>s $7.95 ISBN 0-86668-020-937 TIMEX 1000 & Sinclair ZX-81 Programs for Home, School & Office96 <strong>page</strong>s $8.95 ISBN 0-86668-021-7TIMEX 1000 & Sinclair ZX-81 BASIC Coding Form program worksheets40-sheet pad $2.95 ISBN 0-86668-807-2For the electronics hobbyist:25 Quick-N-Easy Electronics Projects96 <strong>page</strong>s $4.95 ISBN 0-86668-023-325 Electronics Projects for Beginners96 <strong>page</strong>s $4.95 ISBN 0-86668-017-925 Easy-To-Build One-Night & Weekend Electronics Projects96 <strong>page</strong>s $4.95 ISBN 0-86668-010-1Computer program-writing worksheets:Each in tablet of 40 sheets with stiff backingUniversal BASIC Coding FormIBM Personal Computer BASIC Coding FormATARI Computer BASIC Coding FormPocket Computer BASIC Coding FormAPPLE Computer BASIC Coding FormColor Computer BASIC Coding FormTIMEX 1000/Sinclair ZX-81 BASIC Forrn$2.95$2.95$2.95$2.95$2.95$2.95$2.95ISBN: International Standard Book NumberARCsoft PublishersPost Office Box 132Woodsboro, Maryland 21798128


<strong>101</strong> TIMEX 1000/Sinclair ZX-81Programming Tips & Tricksby Edward PageHere's a giant collection of practical, useful, efficient <strong>programming</strong>techniques and operating shortcuts right out of a master programmer'snotebook. Loaded with hints, secrets, shortcuts, tips,<strong>tricks</strong> and easy-to-follow instructions, this book tells you how to handleroutine <strong>programming</strong> chores more quickly, do special effects,make your TIMEX/Sinclair 1000 computer and Sinclair ZX-81 computerwork for you.Each of the <strong>101</strong> tips and <strong>tricks</strong> in this book features a complete,ready-to-type-and-run program which will work all by itself, or as partof a larger set of instructions. All <strong>101</strong> programs in this book have beenthoroughly tested on the TIMEX/Sinclair 1000 and Sinclair ZX-61 computers.Learn insider's how-to secrets for using the exciting BASIC wordsFOR, NEXT, INKEY$, OR, CHA$, INT, LEN, PEEK, AND, STA$, VAL,CLEAR, CLS, DIM, GOSUB, GOTO, IF, THEN, INPUT, LET, PAUSE,PLOT, PRINT, RAND, RETURN, UNPLOT and many more.Sections in this book include Fun & Games, Text On Text, GeeWhiz, Number Crunching, Money Matters, Graphics, and more. There'seven a convenient list of all of the BASIC words and error messagesused in the T/S 1000 and ZX-81.Special techniques are here for graphics, searching, ordering,sorting, error trapping, secret messages, writing and playing games,batting averages, math flasher, ASCII character review, percentages,dollars & cents, decision maker, random numbers, killing time, newsticker, invoicing, wages & hours, passwords, and many, many more.Programs in this book will run without modification on the TIMEX,Sinclair, MicroAce and other computers using the Sinclair version ofthe BASIC <strong>programming</strong> language. The programs also will run, withslight modification to some lines, on TRS-80 models I, II, Ill, 16, Color,PC-1, PC-2, Apple, Atari 400, 600, 800, Commodore Max Machine,VIC-20, 64, Pet, IBM Personal Computer, Sharp PC-1211, PC-1500,Panasonic, Quasar, Hewlett-Packard, and others.ISBN o-88fJ88.020.9

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!