Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This generates random numbers until it matches the user input, it takes roughly 2 minutes to guess the correct numbers.</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace OefeningExaam { class Program { static void Main(string[] args) { Random getal = new Random(); int[] lottotrekking = new int[6]; int[] userInput = new int[6]; bool isLotteryWon = false; int numberOfIterations = 0; Console.WriteLine("Geef je geluksgetallen in &lt;tussen 1 en 42&gt;"); Console.WriteLine("Geef je eerste getal in"); userInput[0] = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Geef je tweede getal in"); userInput[1] = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Geef je derde getal in"); userInput[2] = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Geef je vierde getal in"); userInput[3] = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Geef je vijfde getal in"); userInput[4] = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Geef je zesde getal in"); userInput[5] = Convert.ToInt32(Console.ReadLine()); while (!isLotteryWon) { isLotteryWon = true; // Generate the lottery numbers for (int i = 0; i &lt; lottotrekking.Length; i++) { int newNumber = getal.Next(1, 43); while (Program.IsContained(lottotrekking, newNumber)) newNumber = getal.Next(1, 43); lottotrekking[i] = newNumber; } Console.WriteLine(lottotrekking[0] + "\t " + lottotrekking[1] + "\t " + lottotrekking[2] + "\t " + lottotrekking[3] + "\t " + lottotrekking[4] + "\t " + lottotrekking[5]); //Compare lottery numbers to user input, if they match and are in the same order, the user wins. for (int i = 0; i &lt; lottotrekking.Length; i++) isLotteryWon &amp;= Program.IsContained(lottotrekking, userInput[i]); numberOfIterations++; } Console.WriteLine(string.Format("Lottery won in {0} iterations", numberOfIterations)); Console.ReadLine(); } /// &lt;summary&gt; /// Determines whether the specified number is contained in the collection. /// &lt;/summary&gt; /// &lt;param name="collection"&gt;The collection.&lt;/param&gt; /// &lt;param name="number"&gt;The number.&lt;/param&gt; /// &lt;returns&gt; /// &lt;c&gt;true&lt;/c&gt; if the specified number is contained in the collection; otherwise, &lt;c&gt;false&lt;/c&gt;. /// &lt;/returns&gt; private static bool IsContained(int[] collection, int number) { for (int i = 0; i &lt; collection.Length; i++) { if (collection[i] == number) return true; } return false; } } } </code></pre> <p><img src="https://i.stack.imgur.com/LJw8O.png" alt="enter image description here"> I hope it helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload