05-16-2007, 03:53 PM
Quote:Code:number = INT(RND * 21)
It all works now, are there any ways to make it better, like cutting out useless statements or shortening it?
Well, that instruction can generate the number zero, which you don't allow the player to guess. Seems unfair to me LOL.
Anyway, below is a version that contains no GOTO's.
Also note the use of LCASE$ to allow the user to enter Y as well as y.
Mac
Code:
RANDOMIZE TIMER
Number = 1 + INT(RND * 20)
CLS
FOR Lives = 5 TO 1 STEP -1
PRINT : PRINT "You have"; Lives; "lives."
Guess = 0
DO
INPUT "Enter a number and press return: ", Try
SELECT CASE Try
CASE IS < 0:
PRINT "You may not guess a number less than 0. Please enter another."
CASE 0:
PRINT "You may not guess 0. Please guess again."
CASE IS > 20:
PRINT "You may not guess a number greater than 20. Please enter another."
CASE ELSE:
Guess = Try
END SELECT
LOOP WHILE Guess = 0
IF Guess = Number THEN EXIT FOR
IF Guess < Number THEN
PRINT "Your guess is smaller than the number."
ELSE
PRINT "Your guess is larger than the number."
END IF
NEXT Lives
PRINT
IF Guess = Number THEN
PRINT "Correct, you have won!!!"
ELSE
PRINT "You have run out of lives."
PRINT "The number was"; Number
END IF
DO
PRINT
LINE INPUT "Play again? y = yes , n = no: ", replay$
replay$ = LCASE$(replay$)
IF replay$ = "y" THEN RUN
LOOP WHILE replay$ <> "n"
CLS : SYSTEM