'VB.Net user's number guessing game
I want to make a VB.Net program for my assignment which guesses the user's number using the halving method. However, I have encountered a few problems with my program.
Here is the code:
Dim intGuess As Integer = 50
Dim minimum As Integer = 1
Dim maximum As Integer = 100
Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
btnStart.Enabled = False
lblGuess.Text = $"Is your number {intGuess} ?"
End Sub
Private Sub btnLower_Click(sender As Object, e As EventArgs) Handles btnLower.Click
intGuess = intGuess - (intGuess/ 2)
lblGuess.Text = $"Is your number {intGuess} ?"
End Sub
Private Sub btnHigher_Click(sender As Object, e As EventArgs) Handles btnHigher.Click
intGuess = intGuess + (intGuess / 2)
lblGuess.Text = $"Is your number {intGuess} ?"
End Sub
However the problem is, usually when I press the button that makes the computer guess higher, it will go above 100, and I was wondering how I could tackle this.
Additionally, another problem is that (if for example, I guessed 20) and I keep hitting buttons based on if it should be higher or lower, I will never reach the answer of 20. So if someone could please explain to me what I have done wrong, I would be very grateful!
Solution 1:[1]
With an item in the list, you add a boolean variable to check if it is selected or not.
class Model {
String name;
bool isSelected;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Souvenir |
