Need Help. I am trying to code a multiple choice quiz in C # and having difficul
ID: 3748319 • Letter: N
Question
Need Help. I am trying to code a multiple choice quiz in C # and having difficult getting the program to display the questions and options from the question and options string correctly. . I am also trying to implement a totalScoreCount that is the sum of the multiple choice counter and true false counter. The rest of the program seems to function as it should. Thanks.
Code
namespace Quiz_Program
{
class Program
{
//questions
string[] questions = new string[10]
{
" What Mountain is NICKNAMED the 'SAVAGE MOUNTAIN'",
" Which U.S. STATE has the MOST active volcanoes?",
" What Mountain is CLOSEST to the MOON?",
" What U.S. STATE contains the world’s LARGEST flat-top mountain?",
" Which is the TALLEST MOUNTAIN in the world?",
" What mountains form part of the conventional boundary between the continents of Europe and Asia? ",
" The ATLANTIC OCEAN is home of 75 % of the Earths Volcanoes ?",
" MOUNT SAINT ELIAS(Boundary Peak 186) situated on the Yukon and Alaska Border 25 miles southwest of Mount Logan is the HIGHEST PEAK in NORTH AMERICA", //8
" The HEJAZ MOUNTAINS is the primary mountain range in IRAN?",
" BEN NEVIS is the HIGHEST mountain in the British Isles? ",
};
// question choices
string[,] options = new string[10, 4] // //{ "A","B","C",D"}, or { "T","F"," "," "},
{
{ "MOUNT EVEREST", "K2", "ANNAPURNA", "MATTERHORN" } ,
{ "WASHINGTON", "HAWAII", "ALASKA", "CALIFORNIA" },
{ "NANGA PARABAT", "MOUNT CHIMBORAZO", "MOUNT PANDIM","MOUNT EVEREST"},
{ "UTAH", "ARIZONA", "WYOMING", "COLORADO" , } ,
{ "MOUNT EVEREST", "MOUNT KILIMANJARO","MAUNA KEA", "ACONCAGUA", } ,
{ "APPALACHIAN MOUNTAINS", "ANDEAN MOUNTAINS", "HYMALAYAS", "URAL MOUNTAINS",} ,
{ "True","False", " ", " " },
{ "True","False", " ", " "},
{ "True","False"," ", " "},
{ "True","False", " ", " "}
};
//answer to each question
string[] answers = new string[]
{
"B",
"C",
"C",
"D",
"A",
"D",
"F",
"F",
"F",
"T",
};
// detailed answers
// string[,] detailedAnswers = new string[10]; //{ };
//store second attempt questions
List<int> secondAttemptMCQ = new List<int>();
List<int> secondAttemptQuesTrueFalse = new List<int>();
//true false count
public int trueFalseCount = 0;
public int multipleChoiceCount = 0;
// public int totalScoreCount = multipleChoiceCount + trueFalseCount;
Program()
{
//fill 10 question
questions[0] = "Question 1";
questions[1] = "Question 2";
questions[2] = "Question 3";
questions[3] = "Question 4";
questions[4] = "Question 5";
questions[5] = "Question 6";
questions[6] = "Question 7";
questions[7] = "Question 8";
questions[8] = "Question 9";
questions[9] = "Question 10";
//fill options for first 6 questions // i<6 and J<4
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 4; j++)
{
options[i, j] = "option" + j;
}
}
answers[0] = "A";
answers[1] = "C";
answers[2] = "B";
answers[3] = "D";
answers[4] = "A";
answers[5] = "C";
answers[6] = "T";
answers[7] = "T";
answers[8] = "F";
answers[9] = "T";
}
public void DisplayMCQ(int i, int attempt)
{
Console.WriteLine(" Question " + (i + 1) + ". Multiple Choice");
Console.WriteLine(" A. " + options[i, 0]);
Console.WriteLine(" B. " + options[i, 1]);
Console.WriteLine(" C. " + options[i, 2]);
Console.WriteLine(" D. " + options[i, 3]);
Console.WriteLine(" ");
Console.WriteLine("Please input A, B, C, or D.");
//this is where you read what the user inputs and assign it to a new string
string answer1 = Console.ReadLine();
//deciding answer based on input
if (answer1.ToUpper() == answers[i])
{
if (attempt == 1)
Console.WriteLine(" First Attempt is Correct! ");
// display correct detailed answer code here \\
// display totalScoreCount here\\\
else
Console.WriteLine(" Second Attempt is Correct! ");
multipleChoiceCount++;
// display correct detailed answer code here \\
// display totalScoreCount here\\\
Console.WriteLine(" Next Question...");
Console.Clear();
}
else
{
if (attempt == 2)
Console.WriteLine(" Second Attempt is incorrect! ");
// display correct detailed answer code here \\
// display totalScoreCount here\\\
if (attempt == 1)
secondAttemptMCQ.Add(i);
Console.WriteLine(" Next Question...");
Console.Clear();
}
}
public void DisplayTrueFalse(int i, int attempt)
{
//True or False question
Console.WriteLine(" Question " + (i + 1) + ". True or False:");
Console.WriteLine(" Please input T for true, or F for False");
Console.WriteLine(" ");
string answer2 = Console.ReadLine();
if (answer2.ToUpper() == answers[i])
{
if (attempt == 1)
Console.WriteLine("------First Attempt is Correct!------");
// display correct detailed answer code here \\
// display totalScoreCount here\\\
else
Console.WriteLine("------Second Attempt is Correct!------");
// display correct detailed answer code here \\
// display totalScoreCount here\\\
trueFalseCount++;
Console.WriteLine(" Next Question...");
Console.Clear();
}
else
{
if (attempt == 2)
Console.WriteLine("------Second Attempt is incorrect!------");
// display correct detailed answer code here \\
// display totalScoreCount here\\\
if (attempt == 1)
secondAttemptQuesTrueFalse.Add(i);
Console.WriteLine(" Next Question...");
Console.Clear();
}
}
public void StartQuiz()
{
Console.WriteLine("--------------------------------");
Console.WriteLine("Welcome to the QUIZ!");
Console.WriteLine("--------------------------------");
int attempt = 1;
while (attempt <= 2)
{
if (attempt == 1)
{
int i = 0;
for (i = 0; i < 6; i++)
{
DisplayMCQ(i, attempt);
}
for (; i < 10; i++)
{
DisplayTrueFalse(i, attempt);
}
}
if (attempt == 2)
{
for (int i = 0; i < secondAttemptMCQ.Count; i++)
{
DisplayMCQ(secondAttemptMCQ[i], attempt);
}
for (int i = 0; i < secondAttemptQuesTrueFalse.Count; i++)
{
DisplayTrueFalse(secondAttemptQuesTrueFalse[i], attempt);
}
}
attempt++;
}
}
static void Main(string[] args)
{
Program p = new Program();
p.StartQuiz();
Console.WriteLine("True False Count " + p.trueFalseCount);
Console.WriteLine("Multiple Choice Count " + p.multipleChoiceCount);
}
}
}
Explanation / Answer
using System;
namespace Checkpoint_2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Quiz");
//Variables
bool answerCorrect = false; // will be used to evaluate if answer is correct or not
string[] questions = { "2+2=", "4x5=", "8+2=", "2x100=", "3+3=", "2+100", "2-2=", "1+2=", "3x3=15", "45-5+8=48" }; // will be questions used on test. 8 Multiple choice and 2 true/false
string[] answers = { "a.4 b.2 c.6 d. 10", "a.40 b.20 c.16 d. 11", "a.6 b.12 c.16 d. 10", "a.104 b.200 c.65 d. 102", "a.4 b.2 c.6 d. 10", "a.14 b.200 c.60 d. 102", "a.4 b.2 c.0 d. 10", "a.3 b.2 c.6 d. 102", "true false", " true false" }; // these will stand as answer bank for all questions
string[] correctanswer = { "a", "b", "d", "b", "c", "d", "c", "a", "false", "true" }; //these are the correct answers to all the question. any other selections will be countd as incorrect
int scoreCard = 0; // everyone starts with 0 correct out of ten. once quiz is completed score will be listed as 1-10.
int[] questionsIncorrect = { };
//Welcome To Program
Console.WriteLine("Ryan Hinds, ENGR101- Quiz");
Console.WriteLine();
Console.WriteLine(questions[0]);
Console.WriteLine("Press any key...");
Console.ReadKey();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.