internal static int QueryQuantity() { IInputCondition condition; condition = new IsOneOrTwoDigitsCondition(); InputValidator validator = new InputValidator(condition); bool userInputIsInRange = false; do { string userInput = Console.ReadLine().Trim(); while (!validator.ValidateInput(userInput)) { Console.WriteLine("That input wasn't it, sufferer. Give it another go, it needs to be a whole number."); userInput = Console.ReadLine().Trim(); } int userChoice = int.Parse(userInput); if (userChoice < 1 && userChoice > 80) { Console.WriteLine("That input wasn't it, sufferer. Give it another go, it needs to be between 0 and 50."); continue; } else { userInputIsInRange = true; return(userChoice); } } while (!userInputIsInRange); throw new Exception("User input was processed incorrectly, validated a false input."); }
internal static int ProcessUserInputAgainstPossibleChoices(List <string> possibleOptions) { IInputCondition condition; if (possibleOptions.Count <= 9) { condition = new IsOneDigitCondition(); } else { condition = new IsOneOrTwoDigitsCondition(); } InputValidator validator = new InputValidator(condition); bool userInputIsInRange = false; do { string userInput = Console.ReadLine().Trim(); while (!validator.ValidateInput(userInput)) { Console.WriteLine("That input wasn't it, sufferer. Give it another go, it needs to be a whole number."); userInput = Console.ReadLine().Trim(); } int userChoice = int.Parse(userInput); if (userChoice < 1 || userChoice > possibleOptions.Count) { Console.WriteLine("That input wasn't it, sufferer. Give it another go, it needs to be one of the offered choices."); continue; } else { userInputIsInRange = true; return(userChoice); } } while (!userInputIsInRange); throw new Exception("User input was processed incorrectly, validated a false input."); }