I got my wrist slapped because in an assignment i had a method call itself when an input error was made. I have no idea how to or what to use instead of the code i wrote. I need help to find the correct way on how to do it.
I love to code so i just need a nudge in the right way! 🙂
The code i had written looks like this.
private void SumTheNumbers()
{
Console.Write("Please give the value no "+ index + " :");
if (false == int.TryParse(Console.ReadLine(), out num))
{
//Errormessage if the user did not input an integer.
Console.WriteLine("Your input is not valid, please try again.");
Console.WriteLine();
sum = 0;
SumTheNumbers();
}
else
{
//Calculate the numbers given by user
sum += num;
}
}
The standard way to implement this would be with a while loop.