Advertisement
joemch

Hi Lo Game Structured

Dec 11th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.32 KB | None | 0 0
  1. Module Module1
  2.  
  3.     Sub Main()
  4.         Dim numberToGuess As Integer
  5.         Dim guess As Integer
  6.         Dim win As Boolean = False
  7.         Dim guessoutcome As String
  8.         numberToGuess = RandomNumber()
  9.         Do
  10.             guess = GetInput()
  11.             guessoutcome = isitHiLoOrRight(guess, numberToGuess)
  12.             If guessoutcome = "Right" Then
  13.                 win = True
  14.                 OutputResult(guessoutcome)
  15.             Else
  16.                 win = False
  17.                 OutputResult(guessoutcome)
  18.             End If
  19.         Loop Until win = True
  20.     End Sub
  21.  
  22.     Function RandomNumber() As Integer
  23.         Randomize()
  24.         Return Math.Ceiling(Rnd() * 100)
  25.     End Function
  26.     Function GetInput() As Integer
  27.         '+loads of validation
  28.         Console.WriteLine("sdfghjk")
  29.         Return Console.ReadLine
  30.     End Function
  31.  
  32.     Function isitHiLoOrRight(ByRef guess As Integer, ByVal hiddenNumber As Integer)
  33.  
  34.         If guess = hiddenNumber Then
  35.             Return "Right"
  36.         ElseIf guess > hiddenNumber Then
  37.             Return "Hi"
  38.         Else
  39.             Return "Lo"
  40.         End If
  41.         'do the compare  Return "Hi","lo" or "Right"
  42.  
  43.     End Function
  44.     Sub OutputResult(ByVal outcome As String)
  45.         Console.WriteLine("Your guess was " & outcome)
  46.     End Sub
  47.  
  48. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement