В моем цикле while он запрашивает у пользователя ввод значения и после ввода значения вводит определенные методы. Проблема, с которой я сталкиваюсь, заключается в том, что пользователю предлагается дважды ввести значение (т. Е. Запросить ввести A, B или X. Пользователь вводит значение, а затем программа снова просит ввести A, B или X, не выполняя правильную операцию). Любая помощь, чтобы она работала после ввода, была бы замечательной!, в то время как повторяющиеся входы пользователя в цикле C#
class output
{
static void Main(string[] args)
{
char userInput;
char upper;
Accounts myAccounts = new Accounts();
myAccounts.input();
Console.WriteLine("Enter an A to search account numbers");
Console.WriteLine("Enter a B to average the accounts");
Console.WriteLine("Enter X to quit the program");
Console.WriteLine("Enter an option --->");
userInput = Convert.ToChar(Console.ReadLine());
upper = char.ToUpper(userInput);
while (upper != 'X')
{
if (upper == 'A')
{
myAccounts.search();
Console.WriteLine("Enter an A to search account numbers");
Console.WriteLine("Enter a B to average the accounts");
Console.WriteLine("Enter X to quit the program");
Console.WriteLine("Enter an option --->");
userInput = Convert.ToChar(Console.ReadLine());
upper = char.ToUpper(userInput);
}
else if (upper == 'B')
{
myAccounts.average();
Console.WriteLine("Enter an A to search account numbers");
Console.WriteLine("Enter a B to average the accounts");
Console.WriteLine("Enter X to quit the program");
Console.WriteLine("Enter an option --->");
userInput = Convert.ToChar(Console.ReadLine());
upper = char.ToUpper(userInput);
}
else
Console.WriteLine("You entered an incorrect option, please select new option");
Console.WriteLine("Enter an A to search account numbers");
Console.WriteLine("Enter a B to average the accounts");
Console.WriteLine("Enter X to quit the program");
Console.WriteLine("Enter an option --->");
userInput = Convert.ToChar(Console.ReadLine());
upper = char.ToUpper(userInput);
}
}
}
Srsly .. читайте о методах ... например. 'PrintMenu()' 'EvalInput (ввод char)' и т. Д. –
Что в среднем, методы поиска и ввода? – Tuco