When the input's type is not an integer, the program should fail. However, there are two problems:
- After a letter is typed and I get the "not valid" response, then if the next input is a number, it won't accept it and says "not valid".
How can I make it so when a wrong number is inputted, it stays on the same row and just clears the previous input from the screen (and allows for a retry from the same position)?
static void Main(string[] args) { int firstNum; int Operation = 1; switch (Operation) { case 1: Console.SetCursorPosition(0, 0); Console.Write("Write a number: "); firstNum = ReadInteger(""); Console.ReadKey(); break; } } private static int ReadInteger(string title) { while (true) { if (!string.IsNullOrWhiteSpace(title)) Console.WriteLine(title); string input = Console.ReadLine(); if (int.TryParse(input, out int result)) return result; Console.WriteLine("Sorry, not a valid integer value; please, try again."); Console.ReadKey(); } }