|
Post by anton2012 on Mar 1, 2024 20:18:03 GMT
why does my code always hits an error "DO and LOOP canot both have boolean expresion"??like im really confused,and yes i know it is not finished here is the code:
InfNum=999999 RandomAns=0 PlayerInputNum=0 PRINT "Welcome to the funny number game!" PRINT PRINT "1. Easy(from 1 to 10)" PRINT "2. Normal(from 1 to 100)" PRINT "3. Hard(from 1 to 1000)" PRINT "4. Nightmare(from 1 to inf)" INPUT "Select a difficulty!: " ;choice SELECT CASE choice CASE 1 GOSUB 300 CASE 2 GOSUB 310 CASE 3 GOSUB 320 CASE 4 GOSUB 330 CASE 0 END CASE ELSE PRINT "Invalid choice. Please enter a number from the menu." END SELECT END 300 REM easy difficulty DO RandomAns=int(rnd(1)*10) INPUT "select a number from 1 to 10!:" ;PlayerInputNum IF PlayerInputNum=RandomAns THEN PRINT "CONGRATULATIONS!YOU WON ON EASY MODE!" END END IF IF PlayerInputNum>RandomAns THEN PRINT "Your number is too big" IF PlayerInputNum<RandomAns THEN PRINT "Your number is too small" LOOP UNTIL PlayerInputNum=RandomAns RETURN
|
|
|
Post by tenochtitlanuk on Mar 1, 2024 21:31:09 GMT
Try the following.I've added spaces and indents to make it clearer.
Note also you kept creating a NEW random number while the operator was still trying to guess the one first chosen!
InfNum =999999 RandomAns =0 PlayerInputNum =0
PRINT "Welcome to the funny number game!" PRINT PRINT "1. Easy(from 1 to 10)" PRINT "2. Normal(from 1 to 100)" PRINT "3. Hard(from 1 to 1000)" PRINT "4. Nightmare(from 1 to inf)" INPUT "Select a difficulty!: " ;choice
SELECT CASE choice CASE 1 GOSUB 300 CASE 2 GOSUB 310 CASE 3 GOSUB 320 CASE 4 GOSUB 330 CASE 0 END CASE ELSE PRINT "Invalid choice. Please enter a number from the menu." END SELECT 'END
300 REM easy difficulty RandomAns =int( rnd( 1) *10)
DO INPUT "select a number from 1 to 10!:" ; PlayerInputNum
IF PlayerInputNum =RandomAns THEN PRINT "CONGRATULATIONS!YOU WON ON EASY MODE!" END END IF
IF PlayerInputNum >RandomAns THEN PRINT "Your number is too big"
IF PlayerInputNum <RandomAns THEN PRINT "Your number is too small"
LOOP UNTIL PlayerInputNum =RandomAns
310 RETURN 320 RETURN 330 RETURN
|
|
|
Post by tsh73 on Mar 1, 2024 21:31:22 GMT
It's these two lines, program considers them unfinished IFs
IF PlayerInputNum>RandomAns THEN PRINT "Your number is too big" IF PlayerInputNum<RandomAns THEN PRINT "Your number is too small" You iether type them on a single line (like I chanded below), or end with a separate line with END IF
Also, on a side notem you should put
RandomAns=int(rnd(1)*10) OUT of do/loop - or it will change on each iteration (and "Your number is too big" will mean nothing because number changed each time!)
RandomAns=int(rnd(1)*10) DO INPUT "select a number from 1 to 10!:" ;PlayerInputNum IF PlayerInputNum=RandomAns THEN PRINT "CONGRATULATIONS!YOU WON ON EASY MODE!" END END IF IF PlayerInputNum>RandomAns THEN PRINT "Your number is too big" IF PlayerInputNum<RandomAns THEN PRINT "Your number is too small" LOOP UNTIL PlayerInputNum=RandomAns RETURN
EDIT Ninja'd by John ;)
|
|
|
Post by anton2012 on Mar 2, 2024 10:37:25 GMT
ooo thanks!!
|
|
|
Post by anton2012 on Mar 8, 2024 16:04:10 GMT
im making a joke program where its a 'mind reader' but in my code i have a few problems 1st when you input a number it does not continue for some reason and 2nd how to make it say different text,like i dont want it to always say 'analysing brain waves' here is the code:
InputNum=0 PRINT "WELCOME TO THE MIND READER WHERE I CAN READ YOUR MIND!" INPUT "Enter a number beetwen 1 and 10: "; choice SELECT CASE choice CASE 1 GOSUB 300 CASE 2 GOSUB 310 CASE 3 GOSUB 320 CASE 4 GOSUB 330 CASE 5 GOSUB 340 CASE 6 GOSUB 350 CASE 7 GOSUB 360 CASE 8 GOSUB 370 CASE 9 GOSUB 380 CASE 10 GOSUB 390 CASE 0 END CASE ELSE PRINT "Invalid choice. Please enter a number from the menu." END SELECT END 300 REM Entry for Kaiju InputNum=1 RETURN 310 REM Entry for Kaiju InputNum=2 RETURN 320 REM Entry for Kaiju InputNum=3 RETURN 330 REM Entry for Kaiju InputNum=4 RETURN 340 REM Entry for Kaiju InputNum=5 RETURN 350 REM Entry for Kaiju InputNum=6 RETURN 360 REM Entry for Kaiju InputNum=7 RETURN 370 REM Entry for Kaiju InputNum=8 RETURN 380 REM Entry for Kaiju InputNum=9 RETURN 390 REM Entry for Kaiju InputNum=10 RETURN read dt while dt>0 SCAN print "Scaning brain waves... "; call delay dt print "Done!" read dt wend print print "You're thinking of the number " ;InputNum end sub delay ms t=time$("ms")+ms while t>time$("ms") scan wend end sub data 540 data 987 data 175 data 763 data 271 data 500 data -1
|
|
|
Post by tenochtitlanuk on Mar 8, 2024 17:29:24 GMT
Did you try it with the debug ( red icon to the right of the 'RUN' arrow) It would have shown it getting to the END and halting... It doesn't continue because it exits the SELECT section and hits END!
Here's an ( ugly) GOTO added to send it back for a new input...
InputNum=0 PRINT "WELCOME TO THE MIND READER WHERE I CAN READ YOUR MIND!" [runAgain] INPUT "Enter a number beetwen 1 and 10: "; choice SELECT CASE choice CASE 1 GOSUB 300 CASE 2 GOSUB 310 CASE 3 GOSUB 320 CASE 4 GOSUB 330 CASE 5 GOSUB 340 CASE 6 GOSUB 350 CASE 7 GOSUB 360 CASE 8 GOSUB 370 CASE 9 GOSUB 380 CASE 10 GOSUB 390 CASE 0 END CASE ELSE PRINT "Invalid choice. Please enter a number from the menu." END SELECT goto [runAgain] END 300 REM Entry for Kaiju InputNum=1 RETURN 310 REM Entry for Kaiju InputNum=2 RETURN 320 REM Entry for Kaiju InputNum=3 RETURN 330 REM Entry for Kaiju InputNum=4 RETURN 340 REM Entry for Kaiju InputNum=5 RETURN 350 REM Entry for Kaiju InputNum=6 RETURN 360 REM Entry for Kaiju InputNum=7 RETURN 370 REM Entry for Kaiju InputNum=8 RETURN 380 REM Entry for Kaiju InputNum=9 RETURN 390 REM Entry for Kaiju InputNum=10 RETURN read dt while dt>0 SCAN print "Scaning brain waves... "; call delay dt print "Done!" read dt wend print print "You're thinking of the number " ;InputNum end sub delay ms t=time$("ms")+ms while t>time$("ms") scan wend end sub data 540 data 987 data 175 data 763 data 271 data 500 data -1
Perhaps when you get nearer to what you want one of us can show how to avoid so many jumps to labels/line numbers!
|
|
|
Post by plus on Mar 8, 2024 17:51:58 GMT
why wait?
just make inputNum = choice
toss the salad
300 REM Entry for Kaiju InputNum=1 RETURN 310 REM Entry for Kaiju InputNum=2 RETURN 320 REM Entry for Kaiju InputNum=3 RETURN 330 REM Entry for Kaiju InputNum=4 RETURN 340 REM Entry for Kaiju InputNum=5 RETURN 350 REM Entry for Kaiju InputNum=6 RETURN 360 REM Entry for Kaiju InputNum=7 RETURN 370 REM Entry for Kaiju InputNum=8 RETURN 380 REM Entry for Kaiju InputNum=9 RETURN 390 REM Entry for Kaiju InputNum=10 RETURN
get to the meat and potatoes! ;-))
b = b + ...
|
|
|
Post by anton2012 on Mar 8, 2024 18:13:43 GMT
wait i dont need it to repeat to choose the number!i just need it to choose the number,analyse and THEN loop!plus how to make it print a different word like "detecting thougts" or "scaning for memories"? (no offence to plus the user)
|
|
|
Post by plus on Mar 8, 2024 19:36:26 GMT
Do you mean; if choice = 0 then end ' it all ends here! if choice > 0 and choice < 11 then print "detecting thoughts" : gosub [doSomething] else print "scanning for memories" : gosub [doSumThinElse] goto [runAgain]
b = b + ...
|
|
|
Post by plus on Mar 8, 2024 19:42:27 GMT
wait are you trying to setup for a Guess My Number Game? between 1 and 10 or between 1 and 100 or between 1 and youNameIt?
I am looking at your first post now and trying to read your mind as to what we are trying to do ;-)) Opps first post on 2nd page, not first post this thread.
Update: wait again, is the joke the secret number is 0 ? Ha, you win when you decide to quit! Thats an easy one (for me) to code. That's a 3 liner, i think.
b = b + ...
|
|
|
Post by plus on Mar 8, 2024 19:57:14 GMT
Heres a 2 liner:
[begin] Input "Guess the number I am thinking of ";guess if guess = 0 then print "You win!" else print "Try again" : goto [begin]
b = b + ...
|
|
|
Post by plus on Mar 8, 2024 20:03:24 GMT
3 liner mod, that gives clues now and then:
low = 1000000 : [begin] Input "Guess the number I am thinking of ";guess if guess < low then low = guess else print "Lower!" if guess = 0 then print "You win!" else print "Try again" : goto [begin]
b = b + ...
|
|
|
Post by anton2012 on Mar 8, 2024 20:19:43 GMT
thanks!!!
|
|
|
Post by anton2012 on Mar 8, 2024 20:40:14 GMT
why does the 'mind reading part dosent work????i tried everything! updated code:
nputNum=0 PRINT "WELCOME TO THE MIND READER WHERE I CAN READ YOUR MIND!" INPUT "Enter a number beetwen 1 and 10: "; choice SELECT CASE choice CASE 1 GOSUB 300 CASE 2 GOSUB 310 CASE 3 GOSUB 320 CASE 4 GOSUB 330 CASE 5 GOSUB 340 CASE 6 GOSUB 350 CASE 7 GOSUB 360 CASE 8 GOSUB 370 CASE 9 GOSUB 380 CASE 10 GOSUB 390 CASE 0 PRINT "Exiting the program." END CASE ELSE PRINT "Invalid choice. Please enter a number from the menu." END SELECT END 300 REM Entry for Kaiju InputNum=1 RETURN 310 REM Entry for Kaiju InputNum=2 RETURN 320 REM Entry for Kaiju InputNum=3 RETURN 330 REM Entry for Kaiju InputNum=4 RETURN 340 REM Entry for Kaiju InputNum=5 RETURN 350 REM Entry for Kaiju InputNum=6 RETURN 360 REM Entry for Kaiju InputNum=7 RETURN 370 REM Entry for Kaiju InputNum=8 RETURN 380 REM Entry for Kaiju InputNum=9 RETURN 390 REM Entry for Kaiju InputNum=10 RETURN while dt>0 SCAN print "Detecting thoughts..."; call delay dt print "Done!" read dt print "Scaning brain waves..."; call delay dt print "Done!" read dt print "Searching memories..."; call delay dt print "Done!" read dt print "Conecting to brain..."; call delay dt print "Done!" read dt wend print print "You're thinking of the number " ;InputNum end sub delay ms t=time$("ms")+ms while t>time$("ms") scan wend end sub data 540 data 987 data 175 data 763 data 271 data 500 data -1
|
|
|
Post by Rod on Mar 8, 2024 20:54:18 GMT
Your program is doing what you coded. It takes the number from the user, it then runs the subroutine and returns to the select case block, after that it ends. So it never reaches your mind reading code. So your program flow is not correct. Examples have been given, step through to see the differences.
|
|