My Visual Basic program isn't properly comparing my input guess with the random number answer, I get correct no matter what I input. Can you check my code to find the issue? I am attaching the program requirements in a screenshot of a Word document.
My Visual Basic program isn't properly comparing my input guess with the random number answer, I get correct no matter what I input. Can you check my code to find the issue? I am attaching the program requirements in a screenshot of a Word document.
My Visual Basic program isn't properly comparing my input guess with the random number answer, I get correct no matter what I input. Can you check my code to find the issue? I am attaching the program requirements in a screenshot of a Word document.
My Visual Basic program isn't properly comparing my input guess with the random number answer, I get correct no matter what I input. Can you check my code to find the issue? I am attaching the program requirements in a screenshot of a Word document.
Public Class GuessMyNumberGame
Dim counter As Integer = 0 Dim correctguessed As Integer = 0 Dim total As Integer = 0 Dim answer As Integer Dim guess As Integer = CInt(number.Text) Dim r As System.Random = New System.Random()
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load answer = r.Next(1, 10)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles AcceptButton.Click If (counter <> 5) Then If Not Single.TryParse(number.Text, answer) Then MessageBox.Show("You must enter a numeric value here.", "Bad value", MessageBoxButtons.OK, MessageBoxIcon.Information) number.Text = "" number.Focus() Exit Sub
Else
If guess = answer Then correctguessed = correctguessed + 1 MessageBox.Show("Correct!", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information) number.Text = "" number.Focus()
End If total = total + 1 counter = counter + 1 End If Else MessageBox.Show("Guess limit has been exceeded. I have a new number to guess.", "Start New Game", MessageBoxButtons.OK, MessageBoxIcon.Information) answer = r.Next(1, 10) correctguessed = 0 total = 0 counter = 0 number.Text = "" number.Focus() End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles startButton.Click MessageBox.Show("I have a new number to guess.", "Start New Game", MessageBoxButtons.OK, MessageBoxIcon.Information) number.Text = "" answer = r.Next(1, 10) counter = 0 number.Focus()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles exitButton.Click number.Text = ""
Close()
End Sub End Class
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.