How to resolve the algorithm Guess the number/With feedback step by step in the Scheme 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 Scheme 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 Scheme programming language

Source code in the scheme programming language

(define maximum 5)
(define minimum -5)
(define number (+ (random (- (+ maximum 1) minimum)) minimum))

(display "Pick a number from ") 
(display minimum)
(display " through ")
(display maximum)
(display ".\n> ")
(do ((guess (read) (read))) ((eq? guess number))
        (if (or (>= guess maximum) (< guess minimum))
                (display "Out of range!\n> ")
                (begin
                        (if (> guess number)
                                (display "Too high!\n> "))
                        (if (< guess number)
                                (display "Too low!\n> ")))))
(display "Correct!\n")


  

You may also check:How to resolve the algorithm Loops/For with a specified step step by step in the Groovy programming language
You may also check:How to resolve the algorithm Create an HTML table step by step in the zkl programming language
You may also check:How to resolve the algorithm Tau function step by step in the R programming language
You may also check:How to resolve the algorithm Introspection step by step in the C# programming language
You may also check:How to resolve the algorithm Apply a digital filter (direct form II transposed) step by step in the Common Lisp programming language