How to show how many guesses they used

I don't know what the code is to show how many guesses the user us

Page 1 of 1

1 Replies - 885 Views - Last Post: 09 February 2009 - 02:58 AM Rate Topic: -----

#1 MonkeyBoy2194   User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 489
  • Joined: 09-February 09

How to show how many guesses they used

Post icon  Posted 09 February 2009 - 02:42 AM

The code's working fine I just don't know how to show how many times the user entered a number





Dim Number As Integer
Dim RandomNumber As Integer
Dim guesses As Integer
Private Sub cmdClear_Click()

msg.Cls


End Sub

Private Sub cmdQuit_Click()

End

End Sub

Private Sub cmdStart_Click()

Randomize Timer
RandomNumber = Int(Rnd * 20) + 1
Do
Do
Number = Val(InputBox("Please enter a whole number between 1 to 20"))

If Number <= 1 Then MsgBox ("Please enter a valid number")
If Number >= 20 Then MsgBox ("Please enter a valid number")
Loop Until Number = Valid Or Number > 1 Or Number < 20

Counter = Counter + 1

If Number > RandomNumber Then MsgBox ("The Number you entered is too high.")
If Number < RandomNumber Then MsgBox ("The number you entered is too low.")

Loop Until Number = RandomNumber

MsgBox ("That is the correct number, well done=]")

Is This A Good Question/Topic? 0
  • +

#3 thepeoplescoder   User is offline

  • D.I.C Head
  • member icon

Reputation: 17
  • View blog
  • Posts: 97
  • Joined: 02-February 09

Re: How to show how many guesses they used

Posted 09 February 2009 - 02:58 AM

View PostMonkeyBoy2194, on 9 Feb, 2009 - 01:42 AM, said:

The code's working fine I just don't know how to show how many times the user entered a number





Dim Number As Integer
Dim RandomNumber As Integer
Dim guesses As Integer
Private Sub cmdClear_Click()

	msg.Cls
	
	
End Sub

Private Sub cmdQuit_Click()

	End
	
End Sub

Private Sub cmdStart_Click()

	Randomize Timer
	RandomNumber = Int(Rnd * 20) + 1
	Do
		Do
			Number = Val(InputBox("Please enter a whole number between 1 to 20"))
	  
			If Number <= 1 Then MsgBox ("Please enter a valid number")
			If Number >= 20 Then MsgBox ("Please enter a valid number")
		Loop Until Number = Valid Or Number > 1 Or Number < 20
		
		Counter = Counter + 1

		If Number > RandomNumber Then MsgBox ("The Number you entered is too high.")
		If Number < RandomNumber Then MsgBox ("The number you entered is too low.")
						
	Loop Until Number = RandomNumber
	
	MsgBox ("That is the correct number, well done=]")



Do the following to the cmdStart_Click() sub.

At the beginning, add Dim Counter As Integer and Dim Congrats As String

At your message box that lets the user know they entered the correct number, replace it with this.
Congrats = "That is the correct number, well done=]" + Chr$(13) + Chr$(10)
Congrats = Congrats + "It took you" + Str$(Counter) + " tries."
MsgBox(Congrats)


Was This Post Helpful? 1

Page 1 of 1