public static int ComputeScoreInImportantCategories(QuizRuntimeTemplate runtimeTemplate, int[] answers) { // Get the score itemized by category ItemizedQuizScore itemizedScore = ComputeItemizedScore(runtimeTemplate, answers); int score = 0; // Add up the scores in the important categories foreach (QuizCategory category in runtimeTemplate.Template.ImportantCategories) { score += itemizedScore.GetOrElse(category, 0); } return(score); }
public static ItemizedQuizScore ComputeItemizedScore(QuizRuntimeTemplate runtimeTemplate, int[] answers) { ItemizedQuizScore itemizedScore = new ItemizedQuizScore(); for (int i = 0; i < runtimeTemplate.Questions.Length; i++) { // Get the current question and answer QuizQuestion question = runtimeTemplate.Questions[i]; int answer = answers[i]; // If the answer is within range of the options // then add the option's weight to the total score if (answer >= 0 && answer < question.Options.Length) { QuizOption option = question.Options[answer]; int currentScore = itemizedScore.GetOrElse(question.Category, 0); itemizedScore.Set(question.Category, currentScore + option.Weight); } } return(itemizedScore); }