Console application Lott

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
hello
I have made a code to simular a lotto



using System;<br/>
using System.Collections.Generic;<br/>
using System.Linq;<br/>
using System.Text;<br/>
<br/>
namespace OefExamen<br/>
{<br/>
class Program<br/>
{<br/>
static void Main(string[] args)<br/>
{<br/>
int[] geluksgetal = new int[6];<br/>
int[] lotogetallen = new int[6];<br/>
int aantalpogingen = 0;<br/>
bool juist;<br/>
<br/>
Console.WriteLine("Geef je geluksgetallen");<br/>
Console.WriteLine("Geef je eerste geluksgetal");<br/>
geluksgetal[0] = Convert.ToInt16(Console.ReadLine());<br/>
Console.WriteLine("Geef je tweede geluksgetal");<br/>
geluksgetal[1] = Convert.ToInt16(Console.ReadLine());<br/>
Console.WriteLine("Geef je derde geluksgetal");<br/>
geluksgetal[2] = Convert.ToInt16(Console.ReadLine());<br/>
Console.WriteLine("Geef je vierde geluksgetal");<br/>
geluksgetal[3] = Convert.ToInt16(Console.ReadLine());<br/>
Console.WriteLine("Geef je vijfde geluksgetal");<br/>
geluksgetal[4] = Convert.ToInt16(Console.ReadLine());<br/>
Console.WriteLine("Geef je zesde geluksgetal");<br/>
geluksgetal[5] = Convert.ToInt16(Console.ReadLine());<br/>
<br/>
Random getal0 = new Random();<br/>
Random getal1 = new Random();<br/>
Random getal2 = new Random();<br/>
Random getal3 = new Random();<br/>
Random getal4 = new Random();<br/>
Random getal = new Random();<br/>
<br/>
do<br/>
{<br/>
for (int i = 0; i < lotogetallen.Length; i++)<br/>
{<br/>
lotogetallen = getal.Next(0, 10);<br/>
}<br/>
<br/>
Array.Sort(geluksgetal);<br/>
Array.Sort(lotogetallen);<br/>
<br/>
juist = true;<br/>
<br/>
for (int i = 0; i < geluksgetal.Length; i++)<br/>
{<br/>
//Indien de gok niet juist is<br/>
if (geluksgetal != lotogetallen)<br/>
{<br/>
//zet juist op false<br/>
juist = false;<br/>
//onderbreek de controle aangezien de rest van de array er niet toe doet<br/>
break;<br/>
}<br/>
}<br/>
aantalpogingen++;<br/>
Console.WriteLine(lotogetallen[0] + "t" + lotogetallen[1] + "t" + lotogetallen[2] + "t" + lotogetallen[3] + "t" + lotogetallen[4] + "t" + lotogetallen[5] + "t");<br/>
} while (juist == false);<br/>
<br/>
Console.WriteLine("Je had " + aantalpogingen + " lottotrekkingen nodig");<br/>
Console.ReadLine();<br/>
}<br/>
}<br/>
}

But I get sometimes 2 or more same numbers, have somebody an Idea to get all diferent numbers with a random ?

View the full article
 

Similar threads

Back
Top