Example 2: Guess

NOTE

Use of conditional branching within a loop. This program is a guessing game.

 

   HEADING ''

   HISSCORE=0;  YOURSCORE=0

10     PAGE

   PRINT 'GUESS NUMBERS BETWEEN 0 AND 100'

   PRINT 'MACHINE:  ':HISSCORE:'    ':'YOU:':YOUR SCORE

   PRINT

   NUM=RND(101)

   FOR I=1 TO 6

      PRINT 'GUESS ':I:' ':

      INPUT GUESS

      IF GUESS=NUM THEN

         PRINT

         PRINT 'CONGRATULATIONS, YOU WON!'

         YOURSCORE=YOURSCORE+1

         GOTO 60

      END

      IF GUESS<NUM THEN

                PRINT 'HIGHER'

      IF GUESS>NUM THEN

         PRINT 'LOWER'

   NEXT I

   PRINT

   PRINT 'YOU LOST YOU DUMMY, YOUR NUMBER WAS':NUM

   HISSCORE=HISSCORE+1

60     PRINT

   PRINT 'AGAIN?':

   INPUT X

   IF X = 'NO' THEN STOP

   GOTO 10

END

See Also

Appendix C: mvBASIC Program Examples

General Coding Techniques

Example 1: Triples

Example 3: INV-INQ

Example 4: Format

Example 5: Lot-update

Example 6: Communications

Program