Assembler Developer

Moderators: None (Apply to moderate this forum)
Number of posts: 1752

This Forum Only

Need help creating random number guessing game Posted by kcin00 on 15 Apr 2012 at 4:27 PM
Visual Basic provides a function that can generate random numbers. This function, Rnd, will return a random number, of type Single, between 0 and 1. To get truly random numbers, you must initialize the random number generator using the Randomize statement. Place this statement in the Form Load event.

Create a program that will “think” of a number between 1 and 10. In a Do While loop, use the InputBox function to ask the user to guess the number. Keep track of how many tries it takes the user to guess the number.

Tell the user how many tries it took him to guess the number. Use Select Case to display an appropriate message, based on the number of tries (see below). You may use a label on the form or MsgBox for the output.

To create a random number between 1 and 10, multiply the result of Rnd by 10 and add 1. Rnd * 10 + 1
Use the Int function to convert the result of Rnd to an integer.

Here’s help (use Option Explicit, Val function, appropriate data types and standard prefixes):

Private Sub cmdStart_click( )

‘Declare RandomNumber variable

‘Declare InputNumber variable

‘Declare Counter variable

‘Create random number between 1 and 10
RandomNumber = Int(Rnd * 10 + 1)

‘Use this line of code during testing, then remove it!
Print RandomNumber

‘Get numeric value of user’s guess and accumulate number of guesses until there’s a match
Do While InputNumber <> RandomNumber
InputNumber = Val(InputBox (“Guess my number between 1 and 10”,”Guessing Game”))
Counter = Counter + 1
Loop

‘Display output
Select Case Counter
Case 1
MsgBox (“Wow! You guessed my number in 1 try!”)
Case 2 to 3
MsgBox (“Great job! You guessed my number in “ & Counter & “ tries!”)
Case 4 to 5
.
.
.
End Select
End Sub

Every time that I press the start button to begin guessing numbers, the answer is revealed on the side. How do I stop this?
Re: Need help creating random number guessing game Posted by xiaopig on 17 Apr 2012 at 11:56 PM

TERA , also known as The Exiled Realm of Arborea is a MMORPG currently in development by Bluehole Studio. It was released in South Korea on January 25, 2011 and is set to release in North America and Europe in mid 2011. It is said that the game has typical online RPG features such as quests, crafting and player versus player.And now, we have a large amount of [url=http://www.cheapteragold.us]tera gold[/url] in stock! In addition, we can provide the professional [url=http://www.usteragold.com]power leveling[/url] for players who do not have enough time to make it update.Our [url=http://www.ustera.com/buy-tera-gold/]power leveling[/url] can help you update to a high level in a short time which will not effect your regular work!We can promise you that our transations are very reliable and quickly,and the price of our [url=http://www.usteragold.com]tera gold[/url] is the cheapest! Your satisfactory is our lifeline.

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic