private static void AnswerQuestion(int index, Quiz quiz) { QuizElement quizElement = quiz.GetQuizElement(index); Console.WriteLine(quizElement.GetQuestion()); List <PossibleAnswer> possibleAnswers = quizElement.GetPossibleAnswers(); for (int indexOfPossibleAnswer = 0; indexOfPossibleAnswer < possibleAnswers.Count; indexOfPossibleAnswer++) { Console.WriteLine(indexOfPossibleAnswer.ToString() + ": " + possibleAnswers[indexOfPossibleAnswer].GetPossibleAnswer()); } Console.WriteLine("Type the number corresponding to the correct answer."); try { int indexOfAnswer = Int32.Parse(Console.ReadLine()); if (indexOfAnswer > possibleAnswers.Count - 1 || indexOfAnswer < 0) { Console.WriteLine("This number does not correspond with any of the given answers."); } else if (quiz.EvaluateAnswer(quizElement, indexOfAnswer)) { Console.WriteLine("Your answer was correct, you were awarded one point!"); } else { Console.WriteLine("Your answer was sadly incorrect."); } } catch { Console.WriteLine("This is not a valid number."); } Console.WriteLine("You answered " + quiz.GetScore() + " out of " + quiz.GetAmountQuestions() + " questions correctly."); }
public bool EvaluateAnswer(QuizElement quizElement, int indexOfAnswer) { amountQuestions++; if (quizElement.GetPossibleAnswers()[indexOfAnswer].GetPossibleAnswer() == quizElement.GetCorrectAnswer()) { score++; return(true); } else { return(false); } }