Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
November 24th, 2012, 03:54 PM
 FIR93
Registered User

Join Date: Nov 2012
Posts: 2
Time spent in forums: 1 h 14 m 2 sec
Reputation 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
November 24th, 2012, 04:42 PM
 MrFujin
Lord of the Dance

Join Date: Oct 2003
Posts: 3,340
Time spent in forums: 2 Months 2 Weeks 4 Days 16 h 49 m 18 sec
Reputation Power: 1828
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```

Depend at how you have the rest of the code, it may or may not bee needed.
Where do you ask for user input?

#3
November 24th, 2012, 06:13 PM
 FIR93
Registered User

Join Date: Nov 2012
Posts: 2
Time spent in forums: 1 h 14 m 2 sec
Reputation Power: 0
Quote:
 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

 Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Random Number Guessing Game