#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Random Number Guessing Game


    I don't understand where I am doing something wrong. The instructions is to create a random application that generates a random number in the range of 1 through 100. If it's too low state "too low, try again" and the same for if it's too high.

    (I'm using visual basic)

    So I declared my variables and wrote a code for the procedure. I declared x as my integer. Any advice on how to correct it?
    Thanks for all help

    intNum = rand.Next(100) + 1
    For
    For x > intNum
    MsgBox("Too high, try again")
    Next
    For x < intNum
    MsgBox("Too low, try again")
    Next
    For x = intNum
    MsgBox("You guessed right!")
    Next
    Next
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,730
    Rep Power
    1959
    I assume you want to check the value x against intNum. for this you will have to use the IF statement:
    e.g.
    Code:
    If x > intNum Then
        MsgBox("Too high, try again")
    ElseIf x < intNum Then
        MsgBox("Too low, try again")
    Else
        MsgBox("You guessed right!")
    End If
    You already added a loop, but miss a condition for it.
    Depend at how you have the rest of the code, it may or may not bee needed.
    Where do you ask for user input?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0
    Originally Posted by MrFujin
    I assume you want to check the value x against intNum. for this you will have to use the IF statement:
    e.g.
    Code:
    If x > intNum Then
        MsgBox("Too high, try again")
    ElseIf x < intNum Then
        MsgBox("Too low, try again")
    Else
        MsgBox("You guessed right!")
    End If
    You already added a loop, but miss a condition for it.
    Depend at how you have the rest of the code, it may or may not bee needed.
    Where do you ask for user input?

    I have a text box for the user to put in their guess

IMN logo majestic logo threadwatch logo seochat tools logo