У меня возникли проблемы с моим кодом. Я должен сделать простую игру выбора, и мне нужно ее иметь, чтобы, если пользователь вводит неверный параметр, он приостанавливает историю до тех пор, пока не выберет правильный ответ. Я попробовал обернуть все это через некоторое время (1 == 1) и ввести неверные ответы в консольное окно, и он напечатал «Это был не вариант» бесконечно. Как я могу это исправить? Благодарю.Не соблюдайте неправильный ввод пользователя до получения правильного ввода
// First choice, scene 1 if-statements
while (1 == 1)
{
String firstScene = Console.ReadLine();
firstScene = firstScene.Trim();
String firstChoice = firstScene.ToLower();
Console.WriteLine();
if (firstChoice == "rudely")
{
assholeFactor++;
Console.WriteLine(">>\"You're damn right it was! We've been working on this for years. I thought you'd be happy that all those hours at the office actually amounted to something.\" (Douche factor increased)");
break;
}
if (firstChoice == "nicely")
{
niceFactor++;
Console.WriteLine(">>\"No, it wasn't silly. I can see where you're coming from. I suspect there will be a lot of people with those same type of questions upon the release of the first model.\" (Nice factor increased)");
break;
}
if (firstChoice == "silence")
{
judgement--;
Console.WriteLine(">>You sip your wine and say nothing. (Judgement decreased)");
break;
}
if (firstChoice != "rudely" || firstChoice != "nicely" || firstChoice != "silence")
{
Console.WriteLine("That wasn't an option.");
continue;
}
}
Где цикл? – Steve
Цикл while? Я удалил его, но это было до строки if (firstChoice). – crin
Это просто ошибка, вы должны проверить firstChoice2, а не firstChoice. Если вы не выбрали хорошие имена переменных, вы добавите ошибки. –