I'm trying to search for a "favNum" from a randomly generated array of integers. Assignment asked to use a "While" loop but although I can get the array to print, it all comes unstuck at the loop.
Can anyone give me a clue please? Before I stick my head down the toilet!
Sub Main() Dim favNum As Integer Dim randomNum As New Random Dim i As Integer Dim array(99) As Integer Dim found As Boolean = False Console.WriteLine("What is your favourite number?" & vbNewLine) favNum = Console.ReadLine() Console.WriteLine("") Console.WriteLine("Okay, now press any key to generate 100 random numbers between 1 and 50" & vbNewLine) Console.ReadKey() For i = 0 To 99 array(i) = randomNum.Next(1, 50) Console.Write(array(i) & vbNullChar) Next 'Goes pear-shaped from here While (i <= 100) And (Not found) If i = favNum Then found = True Console.WriteLine("Congratulations! Your number wins...") End If End While If Not found Then Console.WriteLine("I'm sorry, your number wasn't successful.") End If Console.ReadKey() End Sub