I have a doubt in the validation of data entry in C #, for example, in an exercise of calcuclar a sum in C # console mode, as it prevents the execution from hanging and let it run when inserting letters.
For example with this code that takes the average of even and odd numbers.
int cont;
int num;
float contP = 0, acumP = 0;
float contI = 0, acumI = 0;
Console.WriteLine("Digite los numeros que quiera");
cont = int.Parse(Console.ReadLine());
for (int i = 0; i < cont; i++)
{
Console.WriteLine("Digite el numero {0}", (i + 1));
num = int.Parse(Console.ReadLine());
if (num % 2 == 0) {
contP++;
acumP += num;
} else {
contI++;
acumI += num;
}
}
float promP = acumP / contP;
float promI = acumI / contI;
Console.WriteLine("El promedio de los numeros pares es: " + promP);
Console.WriteLine("El promedio de los numeros impares es: " + promI);
What validation do I have to do at the time the user inserts a letter saying "You use a letter" ?. I searched but it does not come out, I found it but for Form
nothing more and not in console