hello so I trying to make this guessing game and i have all the code written down but the last part. When i tired it did not work. Can someone show me how to add the
If their guess is within two of the mystery number, do not tell them if their guess was too high/low but output “Close but no cigar. Try again."
Have the computer randomly select a number between 1 and 100 using a “Reset”
button. Create a separate button “Guess” to prompt the user to guess the number. Let the player
know if their guess is too high or too low. If their guess is within two of the mystery number, do not
tell them if their guess was too high/low but output “Close but no cigar. Try again
code:
Sub Button_Reset()
Row = 1
Cells.Clear
mystery = Application.RandBetween(1, 100)
MsgBox ("The computer has chosen a number between 1 and 100. Click on Try to guess it")
End Sub
Sub Button2_Click()
Dim guess As Integer
guess = InputBox("Enter a number between 1 and 100")
If guess < mystery Then
MsgBox ("Too low. Click 'guess' to try again.")
Cells(Row, 1) = guess
Cells(Row, 2) = "Too Low"
ElseIf guess > mystery Then
MsgBox ("Too high. Click 'Guess' to try again")
Cells(Row, 1) = guess
Cells(Row, 2) = "too High"
Else: guess = mystery
MsgBox ("you have guessed it! The mystery number is " & mystery & ".")
Cells(Row, 1) = guess
Cells(Row, 2) = "you Win"
End If
Row = Row + 1
If their guess is within two of the mystery number, do not tell them if their guess was too high/low but output “Close but no cigar. Try again."
Have the computer randomly select a number between 1 and 100 using a “Reset”
button. Create a separate button “Guess” to prompt the user to guess the number. Let the player
know if their guess is too high or too low. If their guess is within two of the mystery number, do not
tell them if their guess was too high/low but output “Close but no cigar. Try again
code:
Sub Button_Reset()
Row = 1
Cells.Clear
mystery = Application.RandBetween(1, 100)
MsgBox ("The computer has chosen a number between 1 and 100. Click on Try to guess it")
End Sub
Sub Button2_Click()
Dim guess As Integer
guess = InputBox("Enter a number between 1 and 100")
If guess < mystery Then
MsgBox ("Too low. Click 'guess' to try again.")
Cells(Row, 1) = guess
Cells(Row, 2) = "Too Low"
ElseIf guess > mystery Then
MsgBox ("Too high. Click 'Guess' to try again")
Cells(Row, 1) = guess
Cells(Row, 2) = "too High"
Else: guess = mystery
MsgBox ("you have guessed it! The mystery number is " & mystery & ".")
Cells(Row, 1) = guess
Cells(Row, 2) = "you Win"
End If
Row = Row + 1