1
My intention with this code is to show how many numbers are odd and how many are even. (e.g. Odd: 3 Even: 2).
for (int i = 0; i < 6;i++)
{
int SePar, SeImpar, cont;
SePar = 0;
SeImpar = 0;
cont = 0;
if (atividade[i] % 2 == 0)
{
SePar = SePar + 1;
}
if (atividade[i] % 2 != 0)
{
SeImpar = SeImpar + 1;
}
cont = cont + 1;
if (cont == 6)
{
Console.WriteLine("par: " + SePar + "Impar: " + SeImpar);
}
}
Actually the 6 was part of the error, but it is not counting the number.
– Luizz Filipe
If your activity vector[] has no value, it will count no amount. What you asked in the question was one thing and now you want another.
– perozzo
Values are entered by the user previously.
– Luizz Filipe
Yeah, I checked the other questions you asked earlier that you were having second thoughts about that. After you read the user data and fill in the vector, enter the code above. That is, first your program will ask the user to enter the values. Once this is done, the above code will scan your vector with the numbers and count how many are even and how many are odd.
– perozzo
Follow the link as you are now, see what happens in the last part (https://dotnetfiddle.net/tCP7u1).
– Luizz Filipe
I just updated your code. I will edit my answer.
– perozzo
A lot has changed? I am without a computer now.
– Luizz Filipe
No, I just changed what I reported in my reply, took the statement of variables from inside the for and put them out. I updated my answer with your method. Copy it and replace it with your method in fiddle and run. It will work.
– perozzo
I will check as soon as possible and return.
– Luizz Filipe
I stand by.
– perozzo
It worked I still have much to learn, grateful for the help.
– Luizz Filipe
No problem, happy to help. Remember to mark as an answer if I helped you! Thanks.
– perozzo