Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple question - "Duplicate definition"
#11
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
Reply
#12
I just thought of a couple of other minor details....
Rather than having :

INPUT "Enter a number and press return"; guess
You may want to consider the following changes.

Give the player the boundries they may choose within.
(i;e " Enter a number between 1 and 20 and press return" )
Without giving it all away, you may want to use a different style of "INPUT" .
Why? Enter something other than a number and see what happens. :o

Also, using a filter will greatly reduce the amount of code needed.
Granted, it won't give the player so many different things to enjoy reading! Big Grin

To GOTO or not to GOTO, that is the question!
Everyone has their own preferences when it comes to programming.
I personally prefer to use the GOTO command for different reasons, one of which is because it acts (works) the same as JMP (JUMP) :bounce: , in assembly langauge.
adsherm
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)