-1
namespace ThetwelveLabors1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Mythology 101 class, today i will ask you about 10 of the 12 labors of Hercules.");
            Console.WriteLine("what was the first labor of Hercules?");
            Console.ReadLine();            
        }    
     }            
 }

これが私の現在のコードです。ユーザー入力を許可する場所を挿入しようとしています。そして、質問が適切に回答されると、プログラムは次の質問などを 10 の質問に対して行い、終了条件を設定する必要があります。

4

3 に答える 3

2

私があなたなら、まず各質問を含む配列を実装します。

String Questions[] = {"What was the first labor of Hercules"?,... }; // etc etc

String Answers[] = {"The right answer", "The right answer"};

次に、for each loopで、各質問を循環します。foreach ループ内で、答えが間違っている間ループする while ループ。

ユーザーが a を介して入力したConsole.Readline()値が配列内の対応する値と等しい場合Answers、ユーザーは正しく推測したことになり、ブール値を true に設定して while ループを終了させることができ、プログラムは次の問題に進みます。

foreach ループが終了すると、プログラムは終了します。

自分で解決する必要があるため、有用なコードの一部を提供していないことに注意してください。問題がある場合は、いつでも別の質問をすることができますが、これを実装するために最善を尽くしてください:)

于 2013-03-01T22:58:47.193 に答える
0

これを試して

    static void Main(string[] args)
    {
        Console.WriteLine("Welcome to Mythology 101 class, today i will ask you about 10 of the 12 labors of Hercules.");
        Console.WriteLine("what was the first labor of Hercules?");
        while (Console.ReadLine() != "Killing some lion")
        {
            Console.WriteLine("nope");
        }

        Console.WriteLine("Correct!");
        Console.WriteLine();

        Console.WriteLine("What was the second labor of Herclules?");
    } 
于 2013-03-01T23:00:59.567 に答える