protected virtual void OnEvaluate(int questionNumber, string answer) { string userFeedBack = string.Empty; string summaryFeedBack = string.Empty; // go through the answers foreach (Answer a in m_answers) { // find the question, the question has the right answer if (questionNumber == a.QuestionNumber) { // evalute the user provided answer // with the correct answer if (answer == a.CorrectAnswer) { m_numberCorrect++; userFeedBack = $"{a.CorrectAnswer} is the correct answer"; summaryFeedBack = "Correct"; } else { m_numberIncorrect++; userFeedBack = $"{answer} is incorrect \n {a.CorrectAnswer} is the correct answer"; summaryFeedBack = "Incorrect"; } m_numberOfQuestionsAnswered++; m_successPercentage = Decimal.Divide((decimal)m_numberCorrect, (decimal)m_numberOfQuestionsAnswered) * 100.00m; m_successPercentage = (decimal)Math.Round(m_successPercentage); SummaryItem s = new SummaryItem(a.QuestionNumber, a.CorrectAnswer, answer, summaryFeedBack); m_summary.Add(s); break; } } EvaluationEventArgs e = new EvaluationEventArgs(m_numberCorrect, m_numberIncorrect, m_successPercentage, userFeedBack); AnswerEvaluated(this, e); if (questionNumber == m_numberOfQuestions) { OnEnd(); } }
public void Quiz_AnswerEvaluated(object sender, EvaluationEventArgs e) { UpdateStatusPanels(e.CorrectlyAnswered, e.IncorrectlyAnswered, e.SuccessPercentage); MessageBox.Show(e.Feedback, "Multiple Choice Quiz", MessageBoxButtons.OK, MessageBoxIcon.Information); }