0
Hey, here’s my problem. I’m developing an application in c# (console) to learn c# and I’m having a problem that I can’t solve.
First I draw the numbers that will be drawn:
Random rnd = new Random();
int[] numeros = { rnd.Next(1, 49), rnd.Next(1, 49), rnd.Next(1, 49), rnd.Next(1, 49), rnd.Next(1, 49), rnd.Next(1, 49) };
Then I show the numbers and order them (show on the console only for me to do tests):
Array.Sort(numeros);
Console.WriteLine("Números sorteados: ");
foreach (int i in numeros) Console.Write(i + " ");
Now I ask for the guess and create an array to receive the same:
Console.WriteLine("Insere o teu palpite de 6 números: ");
int[] palpites = { int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()) };
The following code is where I see how many combinations are made by comparing the numbers of the arrays:
int combinacao = 0;
if (palpites[0] == numeros[0] || palpites[0] == numeros[1] || palpites[0] == numeros[2] || palpites[0]== numeros[0] || palpites[0] == numeros[4] || palpites[0] == numeros[5])
{
combinacao = combinacao + 1;
}
if(palpites[1] == numeros[0] || palpites[1] == numeros[1] || palpites[1] == numeros[2] || palpites[1] == numeros[3] || palpites[1] == numeros[4] || palpites[1] == numeros[5])
{
combinacao = combinacao + 1;
}
if (palpites[2] == numeros[0] || palpites[2] == numeros[1] || palpites[2] == numeros[2] || palpites[2] == numeros[3] || palpites[2] == numeros[4] || palpites[2] == numeros[5])
{
combinacao = combinacao + 1;
}
if (palpites[3] == numeros[0] || palpites[3] == numeros[1] || palpites[3] == numeros[2] || palpites[3] == numeros[3] || palpites[3] == numeros[4] || palpites[3] == numeros[5])
{
combinacao = combinacao + 1;
}
if (palpites[4] == numeros[0] || palpites[4] == numeros[1] || palpites[4] == numeros[2] || palpites[4] == numeros[3] || palpites[4] == numeros[4] || palpites[4] == numeros[5])
{
combinacao = combinacao + 1;
}
if (palpites[5] == numeros[0] || palpites[5] == numeros[1] || palpites[5] == numeros[2] || palpites[5] == numeros[3] || palpites[5] == numeros[4] || palpites[5] == numeros[5])
{
combinacao = combinacao + 1;
}
Last but not least I reveal the result:
if(combinacao == 0)
{
Console.Write("Não acertou nenhum número.");
}
else if(combinacao == 1)
{
Console.Write("Acertou um número.");
}
else
{
Console.Write("Acertou " + combinacao + " números.");
}
Now comes my problem!
If I repeat my guess several times and that same number is drawn only once it will always count the times I give my guess.
It’s probably something quite simple but as I am very beginner I still can not understand, thank you all for the help!