• Please review our updated Terms and Rules here

Help with CC40 Program

mutantcamel

Experienced Member
Joined
Dec 14, 2007
Messages
76
I'm trying to get this CC-40 program running, the original program is for TI99 Basic.

It's a simple Horse Racing game, where you choose one of 5 horses to bet on and the computer updates you with the race. The string values have been assigned as follows

190 A$(1)="RED RUM"
200 A$(2)="BLUE NUN

etc....


I get the first 2 parts to work, it prints they're off and then a random horse is printed with the line "it's....in the lead.", then that's it, the program just stops and doesn't print out the next bit.

The program part that doesn't work is as follows:

160 RFN=INT(RND*5+1)

410 PRINT “THEY’RE OFF!”: : : :
420 GOSUB 710
430 R=RFN
440 PRINT “IT’S “;A$(R);” IN THE LEAD.”::::
450 GOSUB 710
460 R1=RFN
470 IF R1=R THEN 460
480 PRINT “RUNNING NECK AND NECK IS “;A$(R1);” ::::
etc....

710 FOR K=1 TO 1000
720 NEXT K
730 RETURN

I'm really new to programming so any help would be great!
 
I get the first 2 parts to work, it prints they're off and then a random horse is printed with the line "it's....in the lead.", then that's it, the program just stops and doesn't print out the next bit.

The program part that doesn't work is as follows:

160 RFN=INT(RND*5+1)

410 PRINT “THEY’RE OFF!”: : : :
420 GOSUB 710
430 R=RFN
440 PRINT “IT’S “;A$(R);” IN THE LEAD.”::::
450 GOSUB 710
460 R1=RFN
470 IF R1=R THEN 460
480 PRINT “RUNNING NECK AND NECK IS “;A$(R1);” ::::
etc....

710 FOR K=1 TO 1000
720 NEXT K
730 RETURN

I'm really new to programming so any help would be great!

line 160 sets the variable RFN to a random number. This number is put into R at line 430. It is then put into R1 at line 460. You didn't list whether or not the program sets RFN to another random number before putting the value in R1. Line 470 compares R to R1, and if they are the same, goes back to 460, which has the same number as before. Basically, 460 & 470 become an endless loop.

To fix this, you need to assign a different random number to RFN before putting that value in R1.

At least I think so, it has been years since I've worked in BASIC.

Good luck!
 
Basically what the program should have is 3 different horses in each race. One of the 5 horses is chosen at random and displayed in the first line. If Horse 1 is chosen for example, the program then should display one of the remaning 4 horses on the next line. If horse 1 comes out again, the program should loop until another one is chosen. The horse chosen is displayed in lines 2 and 3. The final horse selected for the final two lines, should then be one of the three remaining horses. The program should loop if either of the first two are generated again.


Here's the full part of the actual race program:

160 RFN=INT(RND*5+1)

410 PRINT “THEY’RE OFF!”: : : :
420 GOSUB 710
430 R=RFN
440 PRINT “IT’S “;A$(R);” IN THE LEAD.”::::
450 GOSUB 710
460 R1=RFN
470 IF R1=R THEN 460
480 PRINT “RUNNING NECK AND NECK IS “;A$(R1);” ::::
490 GOSUB 710
500 PRINT "IT'S ";A$(R1);" IN THE LEAD."::::
510 GOSUB 710
520 R2=RFN
530 IF (R2=R1)+(R2=R) THEN 520
540 PRINT A$(R2);" IS PULLING AHEAD."::::
550 GOSUB 710
560 PRINT "AND IT'S ";A$(R2);" THE WINNER!"::::


710 FOR K=1 TO 1000
720 NEXT K
730 RETURN
 
Last edited:
This is the poor man's debugging technique, however I would have it print out the numbers of your variables so you can see if that's working. Add a line near the appropriate area and Print RFN, R1, R2, etc and make sure their values are correct. Then try seeing if you can determine what line it's really hanging on (a print statement also works well for this). It could be that it's trying to do math on line 530 and getting an error although it should tell you that.

However now that I looked at the code that you have presented, DP is right, if you don't have a new RFN value getting created and you set R2=RFN (and you previously set R1=RFN) you're now saying are R1 and R2 the same? (they are since they were set to the unchanged RFN value) if they're the same do that previous R2=RFN (again not changing) and now see if they're the same. So yeah, it's an endless loop there. I would think you would need a new RFN=int(rnd*5+1) at line 515 or add it to your 710 loop add line 725 RFN=int(rnd*5+1).

- John
 
Thanks for your help. I actually got it working myself by putting that line in numerous places. It was a bit of trial and error, but it seems to be working fine now!

You find that most problems in life often have simple solutions! :D
 
Back
Top