Qbasicnews.com

Full Version: LOOPING problems
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Ok i need some help... what is wrong with this shit...

chances = 0
DO UNTIL chances = 5
num = INT(RND * 10) + 1
INPUT "Guess a nummber between 1 and 20 ", num
IF num <> num THEN
PRINT "You win"
END
ELSEIF num < num THEN
PRINT "To low"
chances = chances + 1
ELSEIF num > num THEN
PRINT "To high"
chances = chances + 1
IF chances = 5 THEN
PRINT "You lose!"
END
LOOP

I only get the error message LOOP without DO
You forgot to add END IF at the end of each IF block.
DOH!!! :oops:
Quote:Ok i need some help... what is wrong with this @£^$...

chances = 0
DO UNTIL chances = 5
num = INT(RND * 10) + 1
INPUT "Guess a nummber between 1 and 20 ", num
IF num <> num THEN
PRINT "You win"
END
ELSEIF num < num THEN
PRINT "To low"
chances = chances + 1
ELSEIF num > num THEN
PRINT "To high"
chances = chances + 1
IF chances = 5 THEN
PRINT "You lose!"
END
LOOP

I only get the error message LOOP without DO

well first of all you can't use the same variable to hold two different value !!!


Code:
num = INT(rnd * 10) + 1
'***        let say num = 8
INPUT "Guess a nummber between 1 and 20 ", num
'***        after above line num = whatever number the user input
'***        so the >>
IF num <> num THEN
'***        will not work !!! cause num will always equal to num duh !!

and also you really must work on the program logic and brush your IF skill the IF also wrong but I guess you already know[/code]
WEASEL,
I've rewritten your program so that it runs and does what you intended. You had several problems including the use of RND to get random numbers. First of all you need to RANDOMIZE TIMER up front to kick off the RND function. Your method of using RND would not produce random numbers between 1 and 20. I substituted a standard method. Take a look at the rest of the code to make sure that's what you intended. I tried to modify your original code as least as possible.
Code:
defint a-z

chances = 0
RANDOMIZE TIMER
' ============================================================================
'   Returns a random integer greater than or equal to the Lower parameter
'   and less than or equal to the Upper parameter.
'
'   RandInt% = INT(RND * (Upper - lower + 1)) + lower
' ============================================================================
num = INT(RND * (20 - 1 + 1)) + 1  'Random number between 1 and 20.

DO UNTIL chances = 5
   INPUT "Guess a number between 1 and 20 ", guess
   IF guess = num THEN
      PRINT "You win"
      END
   ELSEIF guess < num THEN
      PRINT "Too low"
      chances = chances + 1
   ELSEIF guess > num THEN
      PRINT "Too high"
      chances = chances + 1
   END IF
LOOP
' When you fall out of loop, chances are 5.
PRINT "You lose!"
END
*****