I am creating a quiz in C# as console app.
I have a single XML file that contains a) questions b) answers and c) incorrect answers.
I can read questions from my XML File.
However I cannot work out the logic I need to associate the incorrect and correct answers for each randomly generated read question.
Here is a copy of my XML file.
<?xml version="1.0" encoding="utf-8"?>
<Question xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<theQuestion>How many players in a football team?</theQuestion>
<answerA>12</answerA>
<answerB>10</answerB>
<answerC>20</answerC>
<answerD>11</answerD>
<correctAnswer>11</correctAnswer>
<theQuestion>How many minutes in a football game?</theQuestion>
<answerA>90</answerA>
<answerB>45</answerB>
<answerC>60</answerC>
<answerD>77</answerD>
<correctAnswer>90</correctAnswer>
</Question>
Here is part of my code:
ProcessData data = new ProcessData();
//load questions from XML file and store in list
var questions = data.LoadQuizQuestions();
//create a question object
Question q = new Question();
//get a question randomly generated from questions list
int index = new Random().Next(questions.Count);
//display the randomly generated question
Console.WriteLine(questions[index]);
Console.ReadLine();
Here is my LoadQuizQuestions()
public List<string> LoadQuizQuestions()
{
//create empty list to store quiz questions read in from file
List<string> questions = new List<string>();
//load questions from file into list
questions =
XDocument.Load(@"C:\Development\Learning\Files\qsFile.xml").Descendants("theQuestion").Select(o => o.Value).ToList();
//return list of questions
return questions;
}
I would like that when each random question is displayed the associated answers to that question are also displayed and the "correct answer" read into a variable that I can check the user input against.
Please help me understand I know I am close to nailing this :-)
Thank you