Equality Help...Can Figure it out

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mlarsen1982@aol.com

    #1

    Equality Help...Can Figure it out

    Hello everyone

    I am trying to write this application that picks a random number
    between 1-1000, and prompts the user to attempt to enter a number to
    try to guess it. Depending on how far or close the number guessed is
    to random number created by the program, the background will turn blue
    for colder and red for warmer also displaying a label telling the user
    this. If you guess right it turns green and says correct...for some
    reason it only accepts '0' as correct answer. I think there is
    something wrong with the equality statements???

    any help is really appreciated...h ere is my code


    Public Class Form1
    Dim randomObject As New Random()
    Dim randomNumber As Integer


    Public Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load

    txtInput.Enable d = True

    For i As Integer = 1 To 1
    'randomNumber = randomObject.Ne xt(1, 1000)
    i = randomNumber

    Next

    End Sub

    Public Sub txtInput_KeyDow n(ByVal sender As System.Object, ByVal e
    As System.Windows. Forms.KeyEventA rgs) Handles txtInput.KeyDow n


    'Dim array As Integer() = New Integer(999) {}
    Dim number As Integer

    If e.KeyCode = Keys.Enter Then
    number = Convert.ToInt32 (txtInput.Text)


    'For i As Integer = 0 To array.GetUpperB ound(0)
    'array(i) = RandomNumber()
    'Next

    If number = randomNumber Then

    MessageBox.Show ("Correct!")
    Me.BackColor = Color.Green
    txtInput.Enable d = False

    End If

    If number randomNumber Then

    lblHighLow.Text = "Too High"
    Me.BackColor = Color.Red

    End If

    If number < randomNumber Then

    lblHighLow.Text = "Too Low"
    Me.BackColor = Color.Blue

    End If
    End If

    End Sub

  • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

    #2
    RE: Equality Help...Can Figure it out

    It is because you never set randomNumber to any value. It defaults to 0.

    "mlarsen1982@ao l.com" wrote:
    Hello everyone
    >
    I am trying to write this application that picks a random number
    between 1-1000, and prompts the user to attempt to enter a number to
    try to guess it. Depending on how far or close the number guessed is
    to random number created by the program, the background will turn blue
    for colder and red for warmer also displaying a label telling the user
    this. If you guess right it turns green and says correct...for some
    reason it only accepts '0' as correct answer. I think there is
    something wrong with the equality statements???
    >
    any help is really appreciated...h ere is my code
    >
    >
    Public Class Form1
    Dim randomObject As New Random()
    Dim randomNumber As Integer
    >
    >
    Public Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load
    >
    txtInput.Enable d = True
    >
    For i As Integer = 1 To 1
    'randomNumber = randomObject.Ne xt(1, 1000)
    i = randomNumber
    >
    Next
    >
    End Sub
    >
    Public Sub txtInput_KeyDow n(ByVal sender As System.Object, ByVal e
    As System.Windows. Forms.KeyEventA rgs) Handles txtInput.KeyDow n
    >
    >
    'Dim array As Integer() = New Integer(999) {}
    Dim number As Integer
    >
    If e.KeyCode = Keys.Enter Then
    number = Convert.ToInt32 (txtInput.Text)
    >
    >
    'For i As Integer = 0 To array.GetUpperB ound(0)
    'array(i) = RandomNumber()
    'Next
    >
    If number = randomNumber Then
    >
    MessageBox.Show ("Correct!")
    Me.BackColor = Color.Green
    txtInput.Enable d = False
    >
    End If
    >
    If number randomNumber Then
    >
    lblHighLow.Text = "Too High"
    Me.BackColor = Color.Red
    >
    End If
    >
    If number < randomNumber Then
    >
    lblHighLow.Text = "Too Low"
    Me.BackColor = Color.Blue
    >
    End If
    End If
    >
    End Sub
    >
    >

    Comment

    Working...