How to resolve the algorithm Guess the number step by step in the QB64 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Guess the number step by step in the QB64 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 QB64 programming language
Source code in the qb64 programming language
'Task
'Plus features: 1) AI gives suggestions about your guess
' 2) AI controls wrong input by user (numbers outer 1 and 10).
' 3) player can choose to replay the game
Randomize Timer
Dim As Integer Done, Guess, Number
Done = 1
Guess = 0
While Done
Cls
Number = Rnd * 10 + 1
Do While Number <> Guess
Cls
Locate 2, 1
Input "What number have I thought? (1-10)", Guess
If Guess > 0 And Guess < 11 Then
If Guess = Number Then
Locate 4, 1: Print "Well done, you win!"; Space$(20)
Exit Do
ElseIf Guess > Number Then
Locate 4, 1: Print "Too high, try lower"; Space$(20)
ElseIf Guess < Number Then
Locate 4, 1: Print "Too low, try higher"; Space$(20)
End If
Else
Print "Wrong input data! Try again"; Space$(20)
End If
_Delay 1
If Done = 11 Then Exit Do Else Done = Done + 1
Loop
If Done = 11 Then
Locate 4, 1: Print "Ah ah ah, I win and you loose!"; Space$(20)
Else
Locate 4, 1: Print " Sigh, you win!"; Space$(20)
End If
Locate 6, 1: Input "Another play? 1 = yes, others values = no ", Done
If Done <> 1 Then Done = 0
Wend
End
You may also check:How to resolve the algorithm Meissel–Mertens constant step by step in the Maxima programming language
You may also check:How to resolve the algorithm Determine if a string is numeric step by step in the Insitux programming language
You may also check:How to resolve the algorithm Determine if a string has all the same characters step by step in the REXX programming language
You may also check:How to resolve the algorithm First-class functions step by step in the CoffeeScript programming language
You may also check:How to resolve the algorithm Take notes on the command line step by step in the PHP programming language