|
-
Feb 9th, 2013, 08:30 PM
#1
Thread Starter
New Member
Random Numbers Game
Hello Everyone! I was hoping if you can please take a look at my code below and let me know what I need to do in order for the application to work correctly. Here's my assignment:
Code an application that allows the user 10 chances to guess a random generated by the computer. The random number should be an integer from 1 through 50, inclusive. Each time the user makes an incorrect guess, the application should display a message that tells the user either to guess a higher number or to guess a lower number. When the user guesses the random number, the application should display a "Congratulations!" message. However, if the user is not able to guess the random number after 10 tries, the application should display the random number in a message. This what the GUI looks like:

Here's my code:
Option Explicit On
Option Strict On
Option Infer Off
Public Class frmMain
Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Dim intRandom As Integer
Dim randomGenerator As New Random
intRandom = randomGenerator.Next(1, 51)
Const strPROMPT As String =
"Please enter your number. " &
ControlChars.NewLine &
"Click Cancel or leave blank to end."
Const strTITLE As String = "Random Number"
Dim intGuess As Integer
Dim intCount As Integer
Static strDisplayMessage As String
' repeat as long as the user enters a number
Do While intCount <= 10
' get first first number
strDisplayMessage = InputBox(strPROMPT, strTITLE)
'update the counter
intCount += 1
If strDisplayMessage <> String.Empty Then
'convert guess amount to a number
Integer.TryParse(strDisplayMessage, intGuess)
End If
If intGuess = intRandom Then
MessageBox.Show("Congratulations", "Random Number", MessageBoxButtons.OK)
Else
MessageBox.Show("Please guess a higher number.", "Random Number", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else If
MessageBox.Show("Please guess a higher number.", "Random Number", MessageBoxButtons.OK)
End If
Loop
End Sub
End Class
My loop is not working correctly.... any help is greatly appreciated.
Tags for this Thread
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
|