+ 1

How do I not print the same option again?

I am trying to create a console MCQ that prints the questions in a random order and prints the options different every time the user takes the MCQ again. But the same options sometimes get printed together... Here is my code static void printQn() { Questions mcq = new Questions(); Random gen = new Random(); int optionCount = 1; int x = gen.Next(5); Console.WriteLine(mcq.questions[x]); mcq.questionsBool[x] = true; while (optionCount < 5) { int y = gen.Next(4); if (mcq.optionsBool[x, y] == true) { int z = gen.Next(4); Console.WriteLine("[" + optionCount + "]" + mcq.options[x, z]); mcq.optionsBool[x, z] = true; optionCount++; } else if (mcq.optionsBool[x,y] == false) { Console.WriteLine("[" + optionCount + "]" + mcq.options[x, y]); mcq.optionsBool[x, y] = true; optionCount++; } } } static void Main(string[] args) { printQn(); } class Questions { public string[] questions = {"Who was the first Queen of England?", "What is the biggest island on Earth?", "How many Grand Slam singles titles has Roger Federer won? ", "When was the Euro introduced as legal currency on the world market? ", "What year was the first Harry Potter movie released?" }; public bool[] questionsBool = {false,false,false,false,false};

16th Nov 2016, 9:42 AM
ZaiFrost
1 Antwort
0
Here is the rest of my code (it was incomplete) public string[,] options = { { "Queen Elizabeth I","Queen Mary I","Queen Anne" ,"Queen Matilda", }, { "Hawaii" ,"Singapore" ,"Greenland" ,"Luzon ", }, { "19" ,"17" ,"14" ,"15" , }, { "Jan 1 1999" ,"Feb 1 1999" ,"Feb 13 1999","Feb 7 1998" , }, { "2002" ,"1999" ,"2001" ,"2003" }}; public bool[,] optionsBool = { {false, false, false, false }, {false, false, false, false }, {false, false, false, false }, {false, false, false, false }, {false, false, false, false } };
16th Nov 2016, 9:42 AM
ZaiFrost