Roulette Bet

Highlight the following code and save it as a text file called ROU-BET.BAS
Put it in the same folder as GW-BASIC.EXE. Load it and run it.

10 CLEAR :CLS : KEY OFF
20 PRINT "A friend had $3000 but needed $6000 within 24 hours." :PRINT :PRINT
30 PRINT "He went to the casino and bet the high numbers 19-36 on roulette."
40 PRINT "He bet the same amount each spin." :PRINT :PRINT
50 PRINT "How much should he have bet for his best chance?":PRINT :PRINT
60 INPUT "BET ";WAGER
70 IF WAGER > 3000 THEN LET WAGER = 3000
80 PRINT
90 PRINT,"   WIN%","  LOSE%"
100 RANDOMIZE TIMER
110 FOR K = 1 TO 10                'test run over a few cycles
120   WIN=0 :LOSS=0
130   GAMES = 10*WAGER             'the smaller the bet the more games needed
140   FOR CYCLE= 1 TO GAMES
150     BANK = 3000
160     WHILE BANK < 6000 AND BANK > 0
170       BET = WAGER
180       IF BET > (6000-BANK) THEN LET BET = (6000-BANK) 'bet minimum needed  
190       IF BANK < BET THEN LET BET = BANK
200       SPIN = INT(37*RND)
210       IF SPIN >= 19 THEN LET BANK = BANK+BET ELSE BANK = BANK-BET
220     WEND
230     IF BANK >= 6000 THEN LET WIN = WIN+1
240     IF BANK <= 0 THEN LET LOSS = LOSS+1
250   NEXT CYCLE
260   PRINT,USING "####.##";WIN/(WIN+LOSS)*100,
270   PRINT,USING "####.##";LOSS/(WIN+LOSS)*100
280 NEXT K
290 END

Previous | Home | Next