|
Post by 03nm on Jul 22, 2021 0:20:57 GMT
Hi, can someone tell me why the GOSUB here isn’t working?
I’m getting the error RETURN WITHOUT GOSUB ERROR IN 1050 If I’m not mistaken, the GOSUB goes to 1000, then returns to 110
10 PRINT "*** Welcome to Blackjack ***" 20 A = INT(RND(1)*10)+2 30 B = INT(RND(1)*10)+2 40 C = INT(RND(1)*10)+2 50 D = INT(RND(1)*10)+2 60 DEALER=A+B 70 PLAYER=C+D 80 PRINT:PRINT "Dealer has:"A;", ?" 90 PRINT:PRINT "Player has:";C;",";D; 100 GOSUB 1000 110 PRINT:PRINT "Player can (H)it or (S)tay:" 1000 REM HAND CHECK 1010 IF A+B>21 THEN PRINT:PRINT "DEALER BUSTS!!":END 1020 IF C+D>21 THEN PRINT:PRINT "PLAYER BUSTS!!":END 1030 IF A+B=21 THEN PRINT:PRINT "DEALER HAS BLACKJACK !!!":END 1040 IF C+D=21 THEN PRINT:PRINT "PLAYER HAS BLACKJACK !!!":END 1050 RETURN
Thanks for the help
|
|
|
Post by jj0 on Jul 22, 2021 4:44:44 GMT
Hi, can someone tell me why the GOSUB here isn’t working? I’m getting the error RETURN WITHOUT GOSUB ERROR IN 1050If I’m not mistaken, the GOSUB goes to 1000, then returns to 110 10 PRINT "*** Welcome to Blackjack ***" 20 A = INT(RND(1)*10)+2 30 B = INT(RND(1)*10)+2 40 C = INT(RND(1)*10)+2 50 D = INT(RND(1)*10)+2 60 DEALER=A+B 70 PLAYER=C+D 80 PRINT:PRINT "Dealer has:"A;", ?" 90 PRINT:PRINT "Player has:";C;",";D; 100 GOSUB 1000 110 PRINT:PRINT "Player can (H)it or (S)tay:" 1000 REM HAND CHECK 1010 IF A+B>21 THEN PRINT:PRINT "DEALER BUSTS!!":END 1020 IF C+D>21 THEN PRINT:PRINT "PLAYER BUSTS!!":END 1030 IF A+B=21 THEN PRINT:PRINT "DEALER HAS BLACKJACK !!!":END 1040 IF C+D=21 THEN PRINT:PRINT "PLAYER HAS BLACKJACK !!!":END 1050 RETURN Thanks for the help After returning from the GOSUB in line 100 the program will continue naturally to run line 110, then 1000,1010 etc until it reaches 1050. But as in this case there was no GOSUB the RETURN statement has nothing to return to so it errors out.
|
|
|
Post by 03nm on Jul 22, 2021 13:59:50 GMT
After returning from the GOSUB in line 100 the program will continue naturally to run line 110, then 1000,1010 etc until it reaches 1050. But as in this case there was no GOSUB the RETURN statement has nothing to return to so it errors out.
I don't get it: from 100 it'll go to 1000, then 1050, then return to 110 I don't understand why it's saying there's no GOSUB: GOSUB is at line 100
I do have more code after 110, if that makes a difference
|
|
|
Post by vic2020ian on Jul 22, 2021 19:20:02 GMT
After returning from the GOSUB in line 100 the program will continue naturally to run line 110, then 1000,1010 etc until it reaches 1050. But as in this case there was no GOSUB the RETURN statement has nothing to return to so it errors out.
I don't get it: from 100 it'll go to 1000, then 1050, then return to 110 I don't understand why it's saying there's no GOSUB: GOSUB is at line 100
I do have more code after 110, if that makes a difference
After your gosub 1000 completes it returns to 100 and finished that line. The next line is 110, a print statement. After 110 it will run through 1000-1050 again and you trigger a Return but you did not gosub to get there, you continued from 110. You need to either Stop, End or go to the next piece of code after printing then hands. Try adding line 120 Stop
|
|
|
Post by 03nm on Jul 23, 2021 13:09:02 GMT
I think I see what you mean -- thanks!
|
|