Wednesday 10 December 2014

GUESS A NUMBER USING IF_ELSE

GUESS A NUMBER

Now that we know all there is to know about random numbers, it is time to try some in a program. This first program creates a number in the range of 1 to 100. Then you get to guess the number. The computer will provide hints.
10  REM *********************************************************
20  REM *  GUESS1                                              *
30  REM *  Guess a random number selected by a BASIC program    *
40  REM *********************************************************
50  RANDOMIZE TIMER
60  NUMBER% = INT(1 + RND * 100)
70  CLS
80  PRINT "Guess a number in the range 1 and 100"
90  INPUT GUESS%
100 IF GUESS% = NUMBER% THEN GOTO 140
110 IF GUESS% > NUMBER% THEN PRINT "Too High!  Try Again"
120 IF GUESS% < NUMBER% THEN PRINT "Too Low!  Try Again"
130 GOTO 90
140 PRINT "Very Good!  You Guessed the Number."
150 END

ALL Reserved WORDS(CAN't be used as variable name)

         ABS     DATE$   GET
       AND     DEF      GOSUB
       ASC      DEFDBL    GOTO
       ATN      DEFINT         HEX$
       AUTO        DEFSNG            IF
       BEEP         DEFSTR       IMP
       BLOAD         DELETE        INKEY$
       BSAVE                   
       DRAW        INPUT
       CDBL         EDIT       INPUT#
       CHAIN                      ELSE      INPUT$
       CHDIR                      END          INSTR
       CHR$                       ENVIRON      INT
       CINT                       ENVIRON$      INTER$
       CIRCLE                     EOF          IOCTL
       CLEAR                      EQV           IOCTL$
       CLOSE                      ERASE          KEY
       CLS                        ERDEV           KILL
       COLOR                      ERDEV$        LEFT$
       COM                        ERL             LEN
       COMMON                     ERR          LET
       CONT                       ERROR           LINE
       COS                        EXP            LIST
       CSNG                       FIELD         LLIST
       CSRLIN                     FILES      LOAD
       CVD                        FIX            LOC
       CVI                        FNxxxxxxxx     LOCATE
       CVS                        FOR            LOF
       DATA                       FRE              LOG
       LPOS                       POS              STICK
       LPRINT                     PRESET         STOP
       LSET                       PRINT          STR$
       MERGE                      PRINT#         STRIG
       MID$                       PSET            STRING
       MKDIR                      PUT            SWAP
       MKD$                       RANDOMIZE      SYSTEM
       MKI$                       READ           TAB(
       MKS$                       REM            TAN
       MOD                        RENUM           THEN
       MOTOR                      RESET           TIME$
       NAME                       RESTORE       TIMER
       NEW                        RESUME         TO
       NEXT                       RETURN         TROFF
       NOT                        RIGHT$       TRON
       OCT$                       RMDIR     USING
       OFF                        RND          USR
       ON                         RSET        VAL
       OPEN                       RUN            VARPTR
       OPTION                     SAVE      VARPTR$
       OR                         SCREEN      VIEW
       OUT                        SGN             WAIT
       PAINT                      SHELL         WEND
       PEEK                       SIN            WHILE
       PEN                        SOUND         WIDTH
       PLAY                       SPACE$       WINDOW
       PMAP                       SPC(          WRITE
       POINT                      SQR           WRITE#
       POKE                       STEP          XOR

USING MULTIPLE DATA FOR SINGLE READ STATEMENT

The DATA statements can also supply more that one variable with each READ. To do this, separate each piece of data by a comma. The READ must then use more than one variable name. Try this program:
10 FOR X% = 1 TO 3
20   READ FIRST$,SECOND$,THIRD%
30   PRINT FIRST$ SECOND$ THIRD%
40 NEXT X%
50 END
60 DATA Call,me,1
70 DATA Call,me,2
80 DATA Call,me,3
Each piece of data in a DATA statement is called a FIELD. The fields are separated by commas. When they are read, the first field is placed in the first variable name of the READ statement. The second field is placed in the second variable, and so on. The variable type must match the type of data. For example, the integer variable THIRD% in the READ on line 20 can only be used to hold whole numbers. An error message is issued if you try to place letters into an integer variable. This works just like INPUT.
If a field in a DATA statement contains commas, semicolons (;), or many blank spaces, that field must be enclosed in quotation marks.
Each time a READ statement is executed it gathers the input from the next DATA statement. Therefore, one DATA statement must exist for each time READ executes. If a READ is executed after all DATA statements have been processed, BASIC issues the error message Out of Data and the program ends.