/// <summary> /// Gets the number of blacks and whites for the given code from the /// user. /// </summary> public static (int blacks, int whites) GetBlacksWhites(Code code) { while (true) { View.PromptBlacksWhites(code); var input = Console.ReadLine(); if (input is null) { Environment.Exit(0); } var parts = input.Split(','); if (parts.Length != 2) { View.PromptTwoValues(); } else if (!Int32.TryParse(parts[0], out var blacks) || !Int32.TryParse(parts[1], out var whites)) { View.PromptValidInteger(); } else { return(blacks, whites); } } }
/// <summary> /// Gets a transaction amount for the given company. /// </summary> /// <param name="company"> /// The company to buy or sell. /// </param> /// <returns> /// The number of shares to buy or sell. /// </returns> public static int GetTransactionAmount(Company company) { while (true) { View.PromptBuySellCompany(company); var input = Console.ReadLine(); if (input is null) { Environment.Exit(0); } else if (!Int32.TryParse(input, out var amount)) { View.PromptValidInteger(); } else { return(amount); } } }
/// <summary> /// Gets an integer value from the user. /// </summary> private static int GetInteger(Action prompt) { while (true) { prompt(); var input = Console.ReadLine(); if (input is null) { Environment.Exit(0); } if (Int32.TryParse(input, out var result)) { return(result); } else { View.PromptValidInteger(); } } }