I dont know how I did it , i think there has mistakes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ariannaa
    New Member
    • Oct 2013
    • 1

    I dont know how I did it , i think there has mistakes

    Code the click event of the Play Game button to do the following
    i. Generate a random integer between 1 and 100
    ii. Code a loop that will end when the user guesses the number or 10 guesses have failed to find the number.
    iii. Use an inputbox function so that the user can enter each guess.
    iv. If the user does not enter an integer number display an error messagebox, show the answer, and exit the loop. If the user enters a number outside the range of 0 – 100 display an error messagebox, show the answer, and exit the loop.
    v. Show each guess in the Guesses Label using concatenation.
    vi. If the guess is incorrect change the message portion of the InputBox function to “Guess Higher” or “Guess Lower”. Hint: Only use one InputBox – not three different ones.
    vii. Use a messagebox to inform the user that the correct number has been guessed or that ten guesses have failed to guess the number
    Code:
    Private Sub btnPlay_Click(sender As Object, e As EventArgs) Handles btnPlay.Click
            Dim intRandom As Integer
            Dim intAttempt As Integer
            Dim intcount As Integer
    
            Randomize()
            intRandom = CInt(Rnd() * 100) + 1
            intAttempt = Val(InputBox("Enter a number between 1 and 100:"))
            intcount = 1
            Do Until intcount = 10
                If intAttempt < intRandom Then
                    intAttempt = Val(InputBox(CStr(intAttempt) & " Guess Higher.  " & CStr(10 - intcount) & vbNewLine & "Enter another number between 1 and 100:"))
                ElseIf intAttempt > intRandom Then
                    intAttempt = Val(InputBox(CStr(intAttempt) & "Guess Lower. " & CStr(10 - intcount) & vbNewLine & "Enter another number between 1 and 100:"))
                ElseIf intAttempt = intRandom Then
                    Exit Sub
                End If
            Loop
            MsgBox("Sorry. You failed !")
    Last edited by Rabbit; Oct 27 '13, 12:19 AM. Reason: Fixed code tags.
Working...