Good Afternoon. First time poster on this forum and i am quite new to VB.Net
I have the following scenario.
The object of this project is to write a computer program that will allow the
computer to guess a number that you have selected. The computer will make a
guess and you, the player, will tell the computer if it guessed too high, too low, or
that it guessed the number.
The program will also allow the player to start a new game or to exit the program.
PROJECT INSTRUCTIONS:
1. Create a form with a labeled box to display the computers guess.
2. Create a new game and an exit button.
3. Create objects to indicate if the guess was too high, too low, or right on target.
4. Create program code to respond to the player’s indication by selecting and
displaying a new computer guess.
5. When the computer guesses the player’s number, reset the so that a new
game may begin.
I have done all as above and so far my code looks like so
The problem i ran into is that if for example a user has a number 24, when the program makes an initial guess of 50,i want to be able to click low, and the program should generate a lower number say example 22. If i then click higher as my actual number uis 24, the program should not shoot higher than a number it has previously guess incorrect (in this case 50) it should guess anywhere from 22 - 49 and in turn limit the range of the next consecutive guesses it till hits the right number. My code right is guessing as it shuold but not within the limited ranges.
I have done my best to explain this but if anything is still unclear, please let me know and i will respond accordingly
Thanks
I have the following scenario.
The object of this project is to write a computer program that will allow the
computer to guess a number that you have selected. The computer will make a
guess and you, the player, will tell the computer if it guessed too high, too low, or
that it guessed the number.
The program will also allow the player to start a new game or to exit the program.
PROJECT INSTRUCTIONS:
1. Create a form with a labeled box to display the computers guess.
2. Create a new game and an exit button.
3. Create objects to indicate if the guess was too high, too low, or right on target.
4. Create program code to respond to the player’s indication by selecting and
displaying a new computer guess.
5. When the computer guesses the player’s number, reset the so that a new
game may begin.
I have done all as above and so far my code looks like so
VB.NET:
Public Class Form1
Dim Guess As New Random()
Dim HGuess As Integer, LGuess As Integer, current As Integer
Private Sub cmdhigh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdhigh.Click
Dim G As Integer = Guess.Next(1, 100)
current = Integer.Parse(Me.txtguess.Text)
HGuess = G > current
LGuess = G < current
Me.txtguess.Text(Guess.Next(LGuess, HGuess)).ToString()
End Sub
Private Sub cmdnew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdnew.Click
MsgBox("My First Guess")
Me.txtguess.Text = "50"
End Sub
Private Sub cmdlow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdlow.Click
current = Me.txtguess.Text
HGuess = (Guess.Next(current, 101))
LGuess = (Guess.Next(1, current))
Me.txtguess.Text = Integer.Parse(Guess.Next(1, HGuess)).ToString
End Sub
End Class
The problem i ran into is that if for example a user has a number 24, when the program makes an initial guess of 50,i want to be able to click low, and the program should generate a lower number say example 22. If i then click higher as my actual number uis 24, the program should not shoot higher than a number it has previously guess incorrect (in this case 50) it should guess anywhere from 22 - 49 and in turn limit the range of the next consecutive guesses it till hits the right number. My code right is guessing as it shuold but not within the limited ranges.
I have done my best to explain this but if anything is still unclear, please let me know and i will respond accordingly
Thanks