Ejemplo n.º 1
0
        public static void AskSubtractionQuestions(Generator generator)
        {
            Subtract subject         = new Subtract();
            var      questionCount   = generator.QuestionCount;
            var      currentQuestion = 1;

            while (currentQuestion <= questionCount)
            {
                SubtractionProblem p = (SubtractionProblem)subject.GenerateQuestion(generator.Difficulty);
                var isCorrect        = false;
                while (!isCorrect)
                {
                    // Ask question
                    p.PrintQuestion(currentQuestion);

                    // Get answer
                    Console.Write("Answer: ");
                    int  answer      = 0;
                    bool validAnswer = true;
                    try
                    {
                        answer = Convert.ToInt32(Console.ReadLine());
                    }
                    catch (Exception)
                    {
                        validAnswer = false;
                    }

                    // Work out if answer is correct
                    if (validAnswer)
                    {
                        isCorrect = subject.IsCorrect(p, answer);
                        Console.WriteLine(isCorrect ? "Correct!" : "Not quite right. Try again.");
                    }
                }

                currentQuestion++;
            }
        }