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

Source code in the vba programming language

Sub GuessTheNumberWithFeedback()
Dim Nbc&, Nbp&, m&, n&, c&

    Randomize Timer
    m = 11
    n = 100
    Nbc = Int((Rnd * (n - m + 1)) + m)
    Do
        c = c + 1
        Nbp = Application.InputBox("Choose a number between " & m & " and " & n & " : ", "Enter your guess", Type:=1)
        Select Case Nbp
            Case Is > Nbc: MsgBox "Higher than target!"
            Case Is < Nbc: MsgBox "Less than target!"
            Case Else: Exit Do
        End Select
    Loop
    MsgBox "Well guessed!" & vbCrLf & "You find : " & Nbc & " in " & c & " guesses!"
End Sub

  

You may also check:How to resolve the algorithm User input/Text step by step in the Batch File programming language
You may also check:How to resolve the algorithm Gray code step by step in the J programming language
You may also check:How to resolve the algorithm Hofstadter Q sequence step by step in the ZX Spectrum Basic programming language
You may also check:How to resolve the algorithm Averages/Pythagorean means step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Entropy step by step in the Modula-2 programming language