Mind game

Closed
kulestdon10 Posts 3 Registration date Friday October 18, 2013 Status Member Last seen November 23, 2013 - Nov 23, 2013 at 01:13 PM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Dec 10, 2013 at 10:26 AM
Am trying to write a program that will ask the user to enter a number 1-10. The lucky number is 7, if the user enters 7, it will output ''you won!'' else ''try again''. Any other number entered by the user will output the number of trials remaining. The user can only play the game x3, after that it will output ''you lose!'' and exit. Am using code blocks. Thanks
Related:

2 responses

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 555
Dec 5, 2013 at 11:42 AM
Hi Kulestdon10,

You mean something like this?:
Sub MindGame()
Dim nLucky, Counter, uInput As Integer

nLucky = 7
Counter = 2

TryAgain:
uInput = InputBox("Can you guess the lucky number?", "Test your luck")

If uInput = nLucky Then
    MsgBox "CONGRATULATIONS, " & nLucky & " is indeed the lucky number."
Else
    mm = MsgBox("Sorry, that is incorrect. Would you like to try again? (" & Counter & " retry's remaining)", vbOKCancel)
    If mm = vbCancel Then
        MsgBox ("Thanks for playing")
        Exit Sub
    End If
    Counter = Counter - 1
    If Counter = -1 Then
        MsgBox "Sorry, but you are out of retry's, thanks for playing!"
        Exit Sub
    End If
    GoTo TryAgain
End If
End Sub 


Best regards,
Trowa
0
Blocked Profile
Dec 5, 2013 at 11:51 AM
WOW, will you do my homework for me, too, Trowa?
0
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 555
Dec 10, 2013 at 10:26 AM
If you ask nicely, Mark ;).

I guess I'm not so good in recognising homework questions.

Can you forgive me?
0