This text file explains what the source code does, line by line. REM $option k10 REM $option y+,v+,u+,[,] REM $option fNUMGAME.TOS These three lines set the options flags. The k option tells HBASIC how much memory to give to the program. The y+ is to get rid of the main window, v+ to check variables, u+ to underlines in variables, the "[" to select array warnings and "]" to allow undefined sub-programs. The 'f' option sets the name of the output file when compiling. DEF FNgen STATIC y DO y=CINT(RND*1000) LOOP UNTIL y<1000 AND y>0 FNgen=y END DEF Our function called gen. This routines makes sure that a number generated with RND (which is always below 1, so it's multiplied by 1000 to get a decent number, and rounded off with the CINT function) is put into y. This routines makes sure the number is below 1000 but above 0. SUB game STATIC num,low,high,turn,a,a$ RANDOMIZE The RND function would normally give the same number all the time, but this RANDOMIZE function gives a new lot of numbers for the RND to use. num=FNgen turn=0 low=1 high=999 Get our generated number and put it in num, also, make sure the options here (turn is the number of turns, low is the lowest number range and high is the highest number range). DO INCR turn PRINT "Turn:";turn PRINT "The number is between";low;"and";high PRINT Display our info on turn number, low and high ranges. INPUT "What do you think the number is? ",a IF a>999 THEN STOP IF alow THEN low=a IF a>num THEN PRINT "The number is below";a : IF a999 PRINT "Would you like another game?" DO a$=UCASE$(INKEY$) LOOP UNTIL a$="Y" OR a$="N" IF a$="Y" THEN CALL game END SUB Once finished a game, the computer displays "Would you like another game?". The above code involving the INKEY$ gets a key from the keyboard. The UCASE$ turns this code into upper case, if I pressed 'y' then the computer would turn this to 'Y'. If the answer is yes, it will call the routine again. PRINT "Paul's number guessing game. "+CHR$(189)+" Copyright to Paul Jones and Atari Computing" PRINT "1997. Example program using SUB/FUNCTIONS and maths functions as in" PRINT "tutorial #3." CALL game STOP -1 Displays information at the start of the program, and then calls the main game sub routine. The STOP -1 tells the program to quit (once the main game has finished).