I have an application that calculates your gold per minute farmed. I want to make an error report that wouldn\'t allow you to insert any text in the console input where yous hou
Instead of using int.Parse
, you can use int.TryParse, and print a message:
int gold;
while(!int.TryParse(Console.ReadLine(), out gold))
{
Console.WriteLine("Please enter a valid number for gold.");
Console.WriteLine("Inesrt your gold: ");
}
This allows you to re-prompt and handle errors correctly.
In console application you can't control text input (no keypressed event to handle).
This could be a solution
Console.WriteLine("Inesrt your gold: ");
int gold;
while(!int.TryParse(Console.ReadLine(),out gold)){
Console.WriteLine("Please provide a valid gold value");
}
Console.WriteLine("Your gold is : " + gold);