Task

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.



Related tasks

   Bulls and cows
   Bulls and cows/Player
   Guess the number/With Feedback
   Mastermind


 
'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
 