多肢選択プログラムで問題が発生しているようです。私はwhileループで試行する方法を理解していないようです。たとえば、私はあなたに2つの試みを与え、最初の質問が間違っていると言うことができます。それで、あなたは同じ質問でもう一度試してみましょう。私はwhileループを使う必要があると思います。実装する方法を理解できないようです。また、100でない場合にプログラムを再起動できる方法はありますか?C#複数の選択肢の試行と再起動
string First;
int score = 0;
string Second;
TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
Console.Write("Where is the capital of the state of Florida? A.Orlando,B.Tallahassee, C. Miami, or D. Tampa");
First = Console.ReadLine();
switch (First)
{
case "B":
Console.WriteLine("You entered the correct answer!");
break;
case "A":
Console.WriteLine("You entered the wrong answer.");
break;
case "C":
Console.WriteLine("You entered the wrong answer.");
break;
case "D":
Console.WriteLine("You entered the wrong answer.");
break;
default:
Console.WriteLine("You did not enter a correct answer.");
break;
}
if (First == "B")
{
score = score + 50;
Console.WriteLine("Correct!\n" + " score:" + score + "\n");
}
else
{
Console.WriteLine("Wrong!\n" + " score:" + score + "\n");
}
Console.Write("Where is Walt Disney World Park located in Florida? A.Orlando,B.Tallahassee, C. Miami, or D. Tampa");
Second = Console.ReadLine();
switch (Second)
{
case "A":
Console.Write("You entered the correct answer!");
break;
case "B":
Console.WriteLine("You entered the wrong answer.");
break;
case "C":
Console.WriteLine("You entered the wrong answer.");
break;
case "D":
Console.WriteLine("You entered the wrong answer.");
break;
default:
Console.WriteLine("You did not enter a correct answer.");
break;
}
if (Second == "A")
{
score = score + 50;
Console.WriteLine("Correct!\n" + " score:" + score + "\n");
}
else
{
Console.WriteLine("Wrong!\n" + " score:" + score + "\n");
}
正解が1つしかなく残りが間違っているので、 'switch/case'を' if'で置き換えることができます:if(First == 'B'){// Right} else { /間違った} ' – itsme86
それぞれの質問を入れてみてください(つまり、質問と入力文とswitch文を読むこと)。 falseを返す場合は、再度メソッドを呼び出します。また、@ itsme86が述べているように、すべての可能な組み合わせをテストするためにswitch文が本当に必要なわけではありません。入力が正しいかどうかだけは興味があります。 – auburg