I'm not sure where it went wrong.
Sub numguesser()
Dim ans As Integer
Dim ctr As Integer
Dim guess As Integer
Dim deviation As Integer
Dim msg As String
Randomize
ans = Int(Rnd() * 5000 + 1)
ctr = 0
Do
guess = InputBox("guess the number (1 to 5000)", vbQuestion + vbCancel, "")
If guess = "" Then
Exit Sub
End If
ctr = ctr + 1
If ans > guess Then
deviation = ans - guess
Else
deviation = guess - ans
End If
Select Case deviation
Case 0
MsgBox "Congratulations! You have tried " & ctr & " times and get the correct answer of " & ans & ""
Case 1 To 10
MsgBox guess & ": very hot"
Case 11 To 25
MsgBox guess & ": hot"
Case 26 To 100
MsgBox guess & ": cool"
Case 101 To 500
MsgBox guess & ": cold"
Case Is >= 501
MsgBox guess & ": very cold"
End Select
Loop Until ans = guess
End Sub
Bookmarks