Chelsea0270516
New Member
- Joined
- Oct 15, 2015
- Messages
- 32
Hello! I am just working through making this (primarily for fun) and have encountered a weird error - this is a guess the random number game. The code generates a random number & assigns it to the variable myNumber. The user is prompted to guess the number & their guess is assigned to the variable userGuess.
What is weird is no matter what the first userGuess is in relation to the myNumber the answer is always "Higher!" Any guesses after the first one work the way they should.
Anyone have any ideas on what could be causing that? (Or a method of testing to figure that out?)
I made the code display myNumber just to confirm that it wasn't changing between guesses & that wasn't the issue.
I also gave a value to userGuess before the prompt & that didn't change the process either.
(This code doesn't have either of those tests included in it)
What is weird is no matter what the first userGuess is in relation to the myNumber the answer is always "Higher!" Any guesses after the first one work the way they should.
Anyone have any ideas on what could be causing that? (Or a method of testing to figure that out?)
I made the code display myNumber just to confirm that it wasn't changing between guesses & that wasn't the issue.
I also gave a value to userGuess before the prompt & that didn't change the process either.
(This code doesn't have either of those tests included in it)
Code:
Sub DoUntilLoopGuessNumber() Dim myNumber As Integer
myNumber = Int(100 * Rnd) + 1 + Int(100 * Rnd)
InputBox ("Guess my number!")
Dim userGuess As Integer
Do Until userGuess = myNumber
If userGuess > myNumber Then
MsgBox "Lower!"
Else
MsgBox "Higher!"
End If
userGuess = InputBox("Guess my number!")
Loop
MsgBox "Congrats! You guessed it!"
End Sub