02-24-2007, 03:46 AM
This is the code for a simple guessing game, not all variable or labels are that helpfully names but it's so simple it's not hard to understand.
When I attempt to interpret this program the QBasic interpreter 1.1 highlights the first declaration (or possibly it's called an initialisation) of s, saying "Duplicate definition" which I do not understand, as I haven't defined s anywhere else, unless the statements lower down in which I attempt to decrement s have the incorrect syntax.
Any help would be appreciated and I expect you'll all know the answer very quickly
Code:
start: INPUT "Enter a number"; guess
number = INT(RND * 20 + 1)
s = 5
SLEEP
CLS
yyy: IF (guess > 20 OR guess < 0) THEN
PRINT "Your guess is more than 20 or less than zero. Enter another."
GOTO start
ELSEIF (guess > number) THEN
PRINT "You guessed larger than the number"
s -1
GOTO yyy
ELSEIF (guess < number) THEN
PRINT "You guessed a smaller number"
s -1
GOTO yyy
END IF
When I attempt to interpret this program the QBasic interpreter 1.1 highlights the first declaration (or possibly it's called an initialisation) of s, saying "Duplicate definition" which I do not understand, as I haven't defined s anywhere else, unless the statements lower down in which I attempt to decrement s have the incorrect syntax.
Any help would be appreciated and I expect you'll all know the answer very quickly