## Emver

Hey, ive been creating this number guessing game, it works perfectly but I need to add a limit to the amount of turns a user can have.

Any help would be greatly appreciated.

``````Module Module1

Sub Main()

'This program plays a simple number guessing game.
Dim RandNum As Integer
Dim RandomGenerator As New System.Random
Dim UserGuess As Integer
Dim Turns As Integer

Console.Clear()
RandNum = RandomGenerator.Next(1, 10)
Console.WriteLine("{0}", RandNum)
Console.SetCursorPosition(20, 12)
While UserGuess <> RandNum
If UserGuess < RandNum Then
Console.Clear()
Console.SetCursorPosition(20, 14)
Console.WriteLine("{0} Is Wrong. Too Small.", UserGuess)
ElseIf UserGuess > RandNum Then
Console.Clear()
Console.SetCursorPosition(20, 14)
Console.WriteLine("{0} Is Wrong. Too Big.", UserGuess)
End If
Console.SetCursorPosition(20, 12)
End While
Console.SetCursorPosition(20, 14)
Console.WriteLine("{0} Is Correct! Well Done", UserGuess)

End Sub

End Module``````

## crapulency

Hi Emver - something like this:

``````Dim UserGuess As Integer
Dim Turns As Integer

Const MAX_TURNS As Integer = 10
Dim TurnsExceeded As Boolean = False

Console.Clear()
RandNum = RandomGenerator.Next(1, 10)
Console.WriteLine("{0}", RandNum)
Console.SetCursorPosition(20, 12)
While UserGuess <> RandNum
Turns += 1
If Turns <= MAX_TURNS Then
If UserGuess < RandNum Then
Console.Clear()
Console.SetCursorPosition(20, 14)
Console.WriteLine("{0} Is Wrong. Too Small.", UserGuess)
ElseIf UserGuess > RandNum Then
Console.Clear()
Console.SetCursorPosition(20, 14)
Console.WriteLine("{0} Is Wrong. Too Big.", UserGuess)
End If
Console.SetCursorPosition(20, 12)

Else
TurnsExceeded = True
Exit While
End If

End While

Console.SetCursorPosition(20, 14)
If TurnsExceeded Then
Console.Write("Maximum turns exceeded")
Else
Console.WriteLine("{0} Is Correct! Well Done", UserGuess)
End If