Hi I was wondering if anyone could help me with this homework problem of mine? I need to create a program that does this:
Write a program that plays “guess the number” as follows: Your program chooses the number to be guessed by selecting an Integer at random in the range 1–1000. The program then displays the following text in a label:
I have a number between 1 and 1000--can you guess my number?
Please enter your first guess.
A TextBox should be used to input the guess. As each guess is input, the background color should change to red or blue. Red indicates that the user is getting “warmer,” blue that the user is getting “colder.” A Label should display either “Too High” or “Too Low,” to help the user “zero-in” on the correct answer. When the user guesses the correct answer, display “Correct!” in a message box, change the form’s background color to green and disable the TextBox. Provide a Button that allows the user to play the game again. When the Button is clicked, generate a new random number, change the background to the default color and enable the TextBox.
Anyones help would be greatly appreciated...
8 2758 kadghar 1,295
Recognized Expert Top Contributor
I think it would be better if you give it a try by yourself first and then ask here some questions about particular troubles you had while making your program.
If you have no idea, I recomend you to make the whole code into the Command Button click's sub. remember you're working with an object orientated language, dim an integer to generate the number (this should be done outside the command button since you dont want to re-generate it each time the user makes a guess).
Hope that helps (and if it doesnt, take a quick view to the VB help archive to learn the properties and methods and how to use their sintaxis).
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.
Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.
Then when you are ready post a new question in this thread. MODERATOR
The main problem I am having is setting up the number generator. I know it goes something like this.
Dim randomobject As Random = New Random()
Dim nrand As Integer = 0
nrand = randomobject.ne xt(1,1000)
but what else do I need to start?
Here is what I got so far... I am lost though. First off I do not know if I declared everything correctly? Also how do I get the guess to input after it is typed in the box? And how do you configure the warm/cold colors? Please help! - Public Class Form1
-
Dim randomobject As Random = New Random()
-
Dim nrand As Integer = randomobject.Next(1, 1001)
-
-
Dim guess As Integer
-
-
-
-
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
-
guess = TextBox1.Text
-
-
-
-
End Sub
-
-
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
-
If guess < nrand Then
-
Label2.Text = ("Too Low")
-
If guess > nrand Then
-
Label2.Text = ("Too High")
-
Else : MsgBox("Correct")
-
End If
-
End If
-
End Sub
-
End Class
kadghar 1,295
Recognized Expert Top Contributor
The main problem I am having is setting up the number generator. I know it goes something like this.
Dim randomobject As Random = New Random()
Dim nrand As Integer = 0
nrand = randomobject.ne xt(1,1000)
but what else do I need to start?
its easier than that:
dim nrand as integer
nrand = int(rnd * 1000)+1
... and that's it
nrand = int(rnd * 1000)+1
Are you sure that syntax still works in VB.Net?
By the way, if you have a look in the VB Articles area, we have a couple of items there on the subject of generating pseudo-random numbers. (The computer can't generate truly random numbers.)
kadghar 1,295
Recognized Expert Top Contributor
Are you sure that syntax still works in VB.Net?
By the way, if you have a look in the VB Articles area, we have a couple of items there on the subject of generating pseudo-random numbers. (The computer can't generate truly random numbers.)
i didnt see the class... my apologies. :(
Here is what I have so far. I am stuck on getting a play again button to reset the game back to normal and how to get the game to compare the previous guess to the new guess and differenciate between warm or cold. I know i need to use the math.abs() function. Can anyone help.
Public Class Form1
Dim randomobject As Random = New Random()
Dim nrand As Integer = randomobject.Ne xt(1, 1001)
Dim guess As Integer
Dim previousguess As String = guess
Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button2.Click
If guess < nrand Then
Label3.Text = "Too Low"
End If
If guess > nrand Then
Label3.Text = "Too High"
End If
If guess = nrand Then
MsgBox("Correct !")
Me.BackColor = Color.Green
TextBox1.Enable d = False
End If
End Sub
Private Sub Label3_Click(By Val sender As System.Object, ByVal e As System.EventArg s) Handles Label3.Click
End Sub
Private Sub TextBox1_TextCh anged(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox1.TextCh anged
guess = TextBox1.Text
End Sub
End Class
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: anuradha.k.r |
last post by:
hi,
i am writing a socket program in python,both client side and server
side.I've written the client side which is working perfectly
fine(checked it against server program written in C).but as for my
server program written in python it simply hangs.it does not show any
error also.I've tried sample programs available .I don understand what...
|
by: stanlo |
last post by:
Hallo to everyone, i am just begining to learn c++ even though i did
pascal when i studied mathematics in the univesity.i just took on my
self a project which writing a c++ program which does addition,
subtraction, multiplication and division.Highest number of input
characters should be 80 and the program should output eror meseges
like,...
|
by: tyler_durden |
last post by:
thanks a lot for all your help..I'm really appreciated...
with all the help I've been getting in forums I've been able to continue
my program and it's almost done, but I'm having a big problem that I
believe if it's solved, the remaining stuff is easy...
my full program until now is here:
http://www.geocities.com/tom4_h4wk/progmail.zip
the...
|
by: Willing 2 Learn |
last post by:
Below is a program I did to recognize a Finite State Automata for ASCII
(J+H)*. I got that one working but im having trouble getting the NFA
program to work. I really desperately need help!
My NFA has initial states: 2 and 12
ending states 2 and 12
I need help to switch program below from FSA to recognize NFA. I was...
|
by: genestarwing |
last post by:
QUESTION:
Write a program that opens and read a text file and records how many
times each word occurs in the file. Use a binary search tree modified
to store both a word and the number of times it occurs. After the
program has read the file, it should offer a menu with three choices.
the first is to list all the words along with the number of...
| |
by: asif929 |
last post by:
I am trying to write a program which creates four triangles. The
program begins with prompting a user " Enter the size of triangles",
number from 1 to N is the size of four triangles For Example if we
enter 4, the size of four triangles are 4 rows.
In addition, I am also writing a program which i started and failed in
giving the right size...
|
by: asif929 |
last post by:
I need immediate help in writing a function program. I have to write a
program in functions and use array to store them. I am not familiar
with functions and i tried to create it but i fails to run, However, i
simply created this program in arrays and it runs good except i cant
figure out how to compute the standard deviation. The coding is...
|
by: ashishbathini |
last post by:
Hi guys here is my problem ...
this is the source code I Have , honestly I hav no idea how it works bcos its too complicated for me ....
but my problem is ... i hav a freq comonent in it .... what I have to do with it is ... I need to take the output of the second program (which is the freq component ) and this Shud be the input for the...
|
by: C#_Help_needed |
last post by:
I need help with the following question. THANKS :)
Write a program in c# that takes in a directory as a command line
parameter, and returns the longest repeated phrase in ALL text files
in that directory. Assume that all contents of all the files may be
held in memory at the same time. Do not use unsafe code blocks and/
or pointers.
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |