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

Source code in the elena programming language

import extensions;
 
public program()
{
    int randomNumber := randomGenerator.nextInt(1,10);
    console.printLine("I'm thinking of a number between 1 and 10.  Can you guess it?");
    bool numberCorrect := false;
    until(numberCorrect)
    {
        console.print("Guess: ");
        int userGuess := console.readLine().toInt();
        if (randomNumber == userGuess)
        {
            numberCorrect := true;
            console.printLine("Congrats!!  You guessed right!")
        }
        else if (randomNumber < userGuess)
        {
            console.printLine("Your guess was too high")
        }
        else
        {
            console.printLine("Your guess was too low")
        }
    }
}

  

You may also check:How to resolve the algorithm Sequence: smallest number greater than previous term with exactly n divisors step by step in the Ruby programming language
You may also check:How to resolve the algorithm Bézier curves/Intersections step by step in the Raku programming language
You may also check:How to resolve the algorithm Null object step by step in the Nim programming language
You may also check:How to resolve the algorithm Terminal control/Hiding the cursor step by step in the Ring programming language
You may also check:How to resolve the algorithm A+B step by step in the hexiscript programming language