How to resolve the algorithm Guess the number step by step in the XBS programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Guess the number step by step in the XBS programming language
Table of Contents
Problem Statement
Write a program where the program chooses a number between 1 and 10. A player is then prompted to enter a guess. If the player guesses wrong, then the prompt appears again until the guess is correct. When the player has made a successful guess the computer will issue a "Well guessed!" message, and the program exits. A conditional loop may be used to repeat the guessing until the user is correct.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Guess the number step by step in the XBS programming language
Source code in the xbs programming language
const Range:{Min:number,Max:number} = {
Min:number=1,
Max:number=10,
};
while(true){
set RandomNumber:number = math.random(Range.Min,Range.Max);
set Response:string = window->prompt("Enter a number from "+tostring(Range.Min)+" to "+tostring(Range.Max));
if (toint(Response)==RandomNumber){
log("Well guessed!");
stop;
}
}
You may also check:How to resolve the algorithm Fractal tree step by step in the Yabasic programming language
You may also check:How to resolve the algorithm Check input device is a terminal step by step in the Nim programming language
You may also check:How to resolve the algorithm Sequence of non-squares step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Detect division by zero step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Cartesian product of two or more lists step by step in the Groovy programming language