I am new in programming and i am using visual basic. I need to know how to code an application that allows the user 10 chances to guess a random number generated by the computer and the application should display a "congrulations! " message and if user is not able to guess the random number after 10 tries, the application should display the random number in a message. I will be appriciated for the help because this is a very imp assignment which i have to submit in next week.
Random Solution
Collapse
X
-
Tags: None
-
you could use something like:
Code:Dim myval as integer Dim chnc as integer Dim guess as integer Randomize() Myval = int(rnd * 100) Chnc = 1 Do while chnc <= 10 Guess = InputBox("Please Guess a number between 0 and 100", "Chance " & chnc If guess = myval then Msgbox “Congratulations”,,”You Win” Exit Sub Elseif chnc < 10 AND guess <> myval then Msgbox “Sorry you did not Guess the number.” & vbcr & “You have “ & 10 – chnc & “ guesses left.”,,”No Match” Elseif chnc = 10 AND guess <> myval then Msgbox “Sorry you did not Guess the number and have no chances left.”,,”You Lose” End if chnc = chnc + 1 Loop
-
Comment