How to resolve the algorithm Guess the number/With feedback step by step in the COBOL programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Guess the number/With feedback step by step in the COBOL programming language
Table of Contents
Problem Statement
Write a game (computer program) that follows the following rules:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Guess the number/With feedback step by step in the COBOL programming language
Source code in the cobol programming language
IDENTIFICATION DIVISION.
PROGRAM-ID. Guess-With-Feedback.
DATA DIVISION.
LOCAL-STORAGE SECTION.
01 Seed PIC 9(8).
01 Random-Num PIC 99.
01 Guess PIC 99.
PROCEDURE DIVISION.
ACCEPT Seed FROM TIME
COMPUTE Random-Num =
FUNCTION REM(FUNCTION RANDOM(Seed) * 1000, 10) + 1
DISPLAY "Guess a number between 1 and 10:"
PERFORM FOREVER
ACCEPT Guess
IF Guess > Random-Num
DISPLAY "Your guess was too high."
ELSE IF Guess < Random-Num
DISPLAY "Your guess was too low."
ELSE
DISPLAY "Well guessed!"
EXIT PERFORM
END-PERFORM
GOBACK
.
You may also check:How to resolve the algorithm Currying step by step in the Go programming language
You may also check:How to resolve the algorithm Pinstripe/Display step by step in the Locomotive Basic programming language
You may also check:How to resolve the algorithm Here document step by step in the Bracmat programming language
You may also check:How to resolve the algorithm Identity matrix step by step in the C programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bogosort step by step in the Wren programming language