|
-
Nov 24th, 2007, 08:59 AM
#1
Thread Starter
New Member
Random Numbers 1 -50
How do I code an application that allow a user 10 chances to guess a random number from 1-50 and each time it's incorrect it display "Try Again" or guess correctly "Congradulations"
After 10 tries, it display the random number.
I know this is very simple, but I am a stylist who is just learning this stuff.
Thanks,
J
-
Nov 24th, 2007, 09:32 AM
#2
Frenzied Member
Re: Random Numbers 1 -50
Well, are you doing this in a console application or windows application? What are you using for input? I guess it would be safe to assume that you are using VB, but which version? 2003? 2005? 2008? How much experience do you have? Can you write if statement, loops, or handle input and send output?
We're not doing this for you
-
Nov 24th, 2007, 09:58 AM
#3
Thread Starter
New Member
Re: Random Numbers 1 -50
Windows application and for input I am using an inputbox. Yes it is VB 2005, I have little experience and yes I can write if statments, but I get very confused using the loop statements.
Here is what I have so far:
Dim Guess As String
Dim number As Double
Guess = InputBox("Guess the Number")
If number Like "[1-50]" Then
MessageBox.Show("Congradulations")
Else
If number > 50 Then
MessageBox.Show("Lower")
Else
End If
-
Nov 24th, 2007, 10:49 AM
#4
Re: Random Numbers 1 -50
The first thing the code should do on run is create a string and assign it a random number for a value. Then every time a guess is made, it will be compared to the number in the string. Your structure might be:
Dim some string as (create a random number here)
Dim something else to flag when the correct number is chosen
Do while something else
--- Input Box code and results ---
Loop
Last edited by MaximilianMayrhofer; Nov 24th, 2007 at 10:57 AM.
-
Nov 24th, 2007, 11:13 AM
#5
Thread Starter
New Member
Re: Random Numbers 1 -50
So,
I will code the 10 numbers that will be used as the random numbers?
-
Nov 24th, 2007, 12:06 PM
#6
Re: Random Numbers 1 -50
You only need one random number.. and then let them keep guessing it..
If you want to use an input box, then you'll use the code structure I showed above.
Another option is just to have an input text box on a form and a submit button that tells the program to check whether the number in the textbox is correct. In that case, you'll simply have a piece of code in the on-click event of the button that checks whether the number is correct, and you'll need another variable that keeps track of the number of tries.
-
Nov 24th, 2007, 12:21 PM
#7
Thread Starter
New Member
Re: Random Numbers 1 -50
Ok, you confused me even more...., this random number is generated by the computer and the user have only ten tries to guess the correct number.
So, do I use to IF Then statement or the loop statement for this??
-
Nov 24th, 2007, 12:33 PM
#8
Thread Starter
New Member
Re: Random Numbers 1 -50
Dim randomnum1 As Integer
Dim RandomGenerator As New Random
If Me.TextBox1.Text Then
randomnum1 = RandomGenerator.Next(1, 50)
-
Nov 24th, 2007, 05:20 PM
#9
Re: Random Numbers 1 -50
One thing at a time. First try generating the random number. Make it visible so that you can monitor how your coded logic behaves. Afterwards you'll make that number hidden (it'll be stored only in memory).
So see if you can use a button to generate a random number and show that number in a label. Note that RandomGenerator.Next(1, 50) will never generate 50 - the first integer is the inclusive lower bound, the second integer is the exclusive upper bound of the range.
-
Nov 24th, 2007, 11:25 PM
#10
Re: Random Numbers 1 -50
Just try this so you get an idea. Put a label on your form and put this into the click event of a button on your form:
vb.net Code:
Dim rndnumber as Integer
dim rndgenerator as New Random
rndnumber = rndgenerator.Next(1,51)
Label1.Text = rndnumber.ToString
Every time you click the button, you should get a random number between 1 and 50 in your label.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|