jeudi 10 novembre 2016

Looping through a list and matching several conditions

Im trying to create a method that grades a quiz. It works fine if the quiz-question only has one correct answer, but I'm having a hard time handleing multiple correct answers.

I first do a check to see how many correct answers the current question has. If its more than 1 than I need a method that checks if the users answer is a perfect match to the correct answers.

So, if there is a question with 2 correct answers, and the user only checked in 1 of them, he does not get a score.

Any ideas on a method of checking that the number of answers that are correct answers match the correct answers?

I think LINQ would be a good fit here but I'm a total noob on it. Maybe adding all correct answers to a new list and matching with .Contains would be a solution?

The classes look like:

List<Question>

Question-Class
- List<Answers>
    -(string) AnswerText
    -(bool) CorrectAnswer

- List<string> UserAnswerToQuestionText

Pseudo Code:

if (currentquestion has more than one correct answer)
if (UserAnswerText == correctAnswerX && UserAnswerText == correctAnswerY) 

nrofCorrectAnswers++;

Aucun commentaire:

Enregistrer un commentaire