Classic Computer Magazine Archive COMPUTE! ISSUE 40 / SEPTEMBER 1983 / PAGE 252

Timex/Sinclair

Making Change

Michael B. Williams

This game is an excellent educational tool for children and is based on a previously published COMPUTE! article. The author also includes conversion tips for T/S users who want to translate programs originally written for other computers.



Converting a program written for one computer to another computer can get difficult if the program contains machine-dependent features (graphics commands, for instance) or a lot of POKEs. If a program has many such features, it would probably be easier to rewrite it from scratch, once you understand it.
    With modification, many programs published in COMPUTE! and other computer magazines can be converted to run on the Timex/Sinclair. One of these is "Making Change," by Myron Miller (COMPUTE!, February 1983), a program written to help children learn how to count money, divide money, and make change.

Program Conversion
When you transfer any program, your conversion should make up for deficiencies in one area by compensating for them in another area. If your computer has limited graphics, liven it up with sound, and vice versa. The Sinclair has no sound, no color, and limited graphics. But that does not mean we cannot make the program interesting for the user.
    First of all, I decided which version of "Making Change" to convert. I chose the Atari version and went to work. I made multiple statements into individual lines and added STR$ when printing numbers so there would be no pause before they were displayed. Congratulating myself on my persistence, I soon found I wasn't done yet - I had the huge task of debugging ahead. I eliminated one bug only to find several more.
    Finally, I concluded it would be easier to rewrite the program using the listing as a guide. In doing so, I just went about program conversion in a different way. Instead of interpreting the listing line by line, I first tried to understand what it did as a whole. The result was a bug-free program that made it fun to learn about money.
    Each problem is a question about money: how to count it, how to divide it - in short, how to make change. It addresses the child by name and asks him or her directly. If the child answers incorrectly, the program encourages the child to try once more, and the question is repeated. By the third attempt, if the child has not correctly solved the problem, he or she is given the answer.
    A correct answer causes the program to call the machine language routine in line 1. This routine is very important to the program, but you can modify it as you wish.
    Regardless of whether or not the question was answered correctly, the child is given the option of receiving his or her score, continuing, or stopping the program. In this way the child's progress may be evaluated at any stage of the program.

Special Program Notes
Program 1 POKES a machine language routine into the REM statement in line 1. After typing in Program 1, proofread it carefully. Type RUN and ENTER. Test it by using RAND USR 16514. The screen should fill up very fast with inverse spaces. List Program 1 and note that the REM statement in line 1 has been altered. It now contains a machine language subroutine.
Now, delete lines 10-60 and type in Program 2 with line 1 still in memory. When typing in Program 2, use the following instructions where graphics characters appear:

    60: Graphics, SHIFT-S, and SHIFT-D
5010: Underlined letters are inverse video
5115: Graphics and SHIFT-D

Program 1: Machine Language Loader
1 REM XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
10 LET ZZ=16514
20 LET A$="2A0C40017618237EB92604C6807704
    10F5C9"
30 POKE ZZ,16*CODE A$+CODE A$(2)-476
40 LET ZZ=ZZ+1
50 LET A$=A$(3 TO )
60 GOTO 30

Program 2: Making Change
50 SLOW
60 PRINT "
         MAKING CHANGE        
   "
70 PRINT ,,"    TIMEX/SINCLAIR VERSION
       "
80 PRINT ,,"HELLO. PLEASE TELL ME YOUR N
   AME."
90 INPUT N$
100 GOSUB 2000
1000 REM PROBLEMS
1010 REM
1020 LET TP=TP+1
1030 LET CT=INT (100*RND)+1
1040 LET TR=0
1050 LET PT=NOT PT
1060 LET QU=INT (CT/25)
1070 LET DI=INT ((CT-QU*25)/10)
1080 LET NI=INT ((CT-QU*25-DI*10)/5)
1090 LET PE=INT CT-QU*25-DI*10-NI*5
1100 GOTO PT*1000+3000
2000 REM VARIABLES
2010 LET TP=0
2020 LET TC=0
2030 LET TW=0
2040 LET ME=0
2050 LET ML=0
2060 LET FI=0
2070 LET PT=0
2080 LET SCORE=5000
2100 DIM R$(5,10)
2110 FOR X=1 TO 5
2120 LET R$(X)="FANTASTIC.GREAT.    RIGH
     T.    TERRIFIC. VERY GOOD."(X*10-9
     TO X*10)
2130 NEXT X
2999 RETURN
3000 REM COUNT CHANGE
3010 CLS
3020 PRINT TP;") ";N$;", IF I HAVE..."
3040 PRINT ,,TAB 5;QU;" QUARTER"+("S" AN
     D QU<>1)
3050 PRINT ,,TAB 5;DI;" DIME"+("S" AND D
     I<>1)
3060 PRINT ,,TAB 5;NI;" NICKEL"+("S" AND
      NI<>1);", AND "
3070 PRINT ,,TAB 5;PE;" PENN"+("Y" AND P
     E=1)+("IES" AND PE<>1),", THEN"
3080 PRINT ,,"HOW MUCH CHANGE DO I HAVE?
      ";
3110 INPUT CH
3120 PRINT CH
3130 LET TR=TR+1
3140 IF CH=CT THEN GOTO 3500
3150 PRINT „ "NOPE. THAT'S "+STR$ ABS (C
     T-CH)+" CENT"+("S" AND ABS (CH-CT)<
     >1)+" TOO "+("MUCH." AND CH>CT)+("L
     ITTLE." AND CH<CT)
3160 LET ML=ML+1
3165 IT TR=1 THEN LET TW=TW+1
3170 IF TR=3 THEN GOTO 3210
3180 PRINT ,"PRESS ENTER TO TRY AGAIN."
3190 IF INKEY$="" THEN GOTO 3190
3200 GOTO 3000
3210 PRINT ,"THE ANSWER IS "+STR$ CT+",
      "+N$+"."
3220 GOTO SCORE
3500 LET ZZ=USR 16514
3510 PRINT
3520 PRINT N$+", "+"THATS "+R$(INT (5*RN
     D)+1)
3530 LET ZZ=USR 16514
3540 IF TR=1 THEN LET TC=TC+1
3550 LET ME=ME+1
3560 GOTO SCORE
4000 REM GIVE CHANGE
4010 CLS
4020 PRINT STR$ TP+") "+N$+", IF I HAVE
     "+STR$ CT+" CENT"+("5" AND CT<>1)+"
     ,"
4030 PRINT ,,"HOW MANY QUARTERS DO I HAV
     E? "
4040 INPUT Q
4050 PRINT Q ,,TAB 9;"DIMES? ";
4060 INPUT D
4070 PRINT D ,,TAB 9;"NICKELS? ";
4080 INPUT N
4090 PRINT N ,,TAB 9;"PENNIES? ";
4100 INPUT P
4110 PRINT P
4115 LET TR=TR+1
4120 IF Q=INT Q AND N=INT N AND D=INT D
     AND P=INT P THEN GOTO 4200
4130 PRINT „ "THATS NOT FAIR, USING DECI
     MALS. YOU MUST PAY A FINE, "+N$+"."
4140 LET FI=FI+1
4150 GOTO 4220
4200 IF 25*Q+10*D+5*N+P=CT THEN GOTO 440
     0
4205 PRINT ,"NOT QUITE--THAT MAKES "+ST
     R$ (25*Q+10*D+5*N+P)+" CENTS."
4210 LET ML=ML+1
4215 IF TR=1 THEN LET TW=TW+1
4220 IF TR=3 THEN GOTO 4300
4230 PRINT ,,"PRESS ENTER TO TRY ONCE MO
     RE."
4240 IF INKEY$="" THEN GOTO 4240
4250 GOTO 4000
4300 PRINT ,,"A THOUSAND TIMES NO, "+N$+
     "."
4310 PRINT ,,"I WOULD HAVE "+STR$ QU;" Q
     UARTER"+("S" AND QU<>1);TAB13;STR$
     DI+" DIME"+("S" AND DI<>1)
4320 PRINT TAB 13;STR$ NI+" NICKEL"+("S"
      AND NI<>1);", AND ";TAB 13;STR$ PE
     +" PENN"+("Y" AND PE=1)+("IES" AND
     PE<>1);"."
4330 GOTO SCORE
4400 IF Q=QU AND D=DI AND N=NI AND P=PE
     THEN GOTO 4500
4410 PRINT ,,"TRUE, BUT YOU COULD HAVE U
     SED   FEWER COINS, "+N$+"."
4420 GOTO 4210
4500 LET ZZ=USR 16514
4510 PRINT
4520 PRINT "HEY..."+R$(INT (5*RND)+1)
4530 LET ZZ=USR 16514
4540 LET ME=ME+1
4550 IF TR=1 THEN LET TC=TC+1
5000 REM SCORE
5010 PRINT ,,"PRESS C TO CONTINUE, S FOR
      YOUR SCORE, OR ENTER TO STOP."
5020 LET I$=INKEY$
5030 IF I$="" THEN GOTO 5020
5040 IF I$="C" THEN GOTO 1000
5050 IF I$<>"S" AND I$<>CHR$ 118 THEN GO
     TO 5020
5100 CLS
5110 PRINT N$+"S "+("FINAL " AND I$=CHR$
      118)+"SCORE:"
5115 PRINT "
     "
5120 PRINT ,,"NUMBER OF PROBLEMS: "+STR$
      TP
5130 PRINT ,,"TOTAL CORRECT: "+STR$ TC
5140 PRINT ,,"TOTAL WRONG: "+STR$ TW
5150 PRINT ,,"PERCENT CORRECT: "+STR$ IN
     T ((TC/TP)*100)
5160 PRINT ,,,,"MONEY EARNED: "+STR$ ME
5170 PRINT ,,"MONEY LOST: "+STR$ ML
5180 PRINT ,,"FINES: "+STR$ FI
5190 LET X=ME-ML-FI
5200 PRINT ,,("I OWE YOU" AND X>0)+("YOU
      OWE ME" AND X<0)+" "+STR$ ABS X+"
     CENT"+("S" AND ABS X<>1);"."
5210 IF I$=CHR$ 118 THEN GOTO 5250
5220 PRINT ,,"PRESS ENTER TO CONTINUE "
5230 IF INKEY$="" THEN GOTO 5230
5240 GOTO 1000
5250 PRINT ,,"BYE, "+N$+". I HAD FUN."
9997 STOP
9998 SAVE "MAKING CHANGE"
9999 RUN