SHARE
TWEET

Untitled

a guest Jun 1st, 2019 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.       * Guessing Game: Guess value between 1 and 1000
  2.        IDENTIFICATION DIVISION.
  3.        PROGRAM-ID. RANDOM-GUESS.
  4.        AUTHOR.  Jesse Racine.
  5.        DATA DIVISION.
  6.        WORKING-STORAGE SECTION.
  7.        01 RandNum      PIC 9999.                
  8.        01 GuessedNum   PIC 9999 VALUE 0.
  9.            88 Valid-Value  VALUE 0001 THRU 1000.
  10.        01 DateSeed     PIC 9(16).
  11.        PROCEDURE DIVISION.
  12.            Begin.
  13.             MOVE FUNCTION CURRENT-DATE(1:16) TO DateSeed.
  14.             COMPUTE RandNum = Function RANDOM(DateSeed) * 1000 + 1            
  15.             PERFORM UNTIL 1 <> 1    
  16.                PERFORM Get-Guess WITH TEST AFTER UNTIL Valid-Value
  17.                IF GuessedNum = RandNum THEN
  18.                   DISPLAY "You guessed correctly"
  19.                   STOP RUN
  20.                END-IF
  21.                IF GuessedNum < RandNum THEN
  22.                   DISPLAY "Your guess was lower than the target"
  23.                END-IF
  24.                
  25.                IF GuessedNum > RandNum THEN
  26.                   DISPLAY "Your guess was higher than the target"
  27.                END-IF
  28.             END-PERFORM
  29.             STOP RUN.
  30.            Get-Guess.
  31.                DISPLAY "Guess Number between 1 - 1000"
  32.                ACCEPT GuessedNum
  33.                IF NOT Valid-Value THEN
  34.                    DISPLAY "Your guess was not valid, try again"
  35.                END-IF.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top