Hello, I just need help with a quiz grading program I am writing. I only need to display the correct answer from a text file upon an incorrect user input here:
if (ans == questions[i].getCorrectNumber())
{
cout << "Correct!" << endl;
nRight++;
}
else
{
cout << "Sorry that's Incorrect. The correct answer is: " << endl;
//????
//Need help displaying correct answer
nWrong++;
}
cout << "Welcome to My Awesome Quiz-o-Matic!" << endl;
int ans = 0;
int nWrong = 0;
int nRight = 0;
const int num_of_questions = 5;
Question questions[num_of_questions];
cout << "Question for Student\n";
cout << "____________________\n";
//Call initQuestions() function to load array with questions.
initQuestions(questions, num_of_questions);
//Use a loop to prompt student with question and read answer.
for (int i = 0; i < num_of_questions; i++)
{
//Call displayQuestion to display question.
displayQuestion(questions[i]);
//use cin >> ans to read student answer.
cin >> ans;
//If the answer is correct, display correct
// refer to specific question object
if (ans == questions[i].getCorrectNumber())
{
cout << "Correct!" << endl;
nRight++;
}
else
{
cout << "Sorry that's Incorrect. The correct answer is: " << endl;
//????
//Need help displaying correct answer
nWrong++;
}
if (ans == questions[i].getCorrectNumber())
{
cout << "Correct!" << endl;
nRight++;
}
else
{
cout << "Sorry that's Incorrect. The correct answer is: " << endl;
let me see if I understand.
so if the user doesn't input `questions[i].getCorrectNumber()' you tell him that his answer is incorrect, because he should have put `questions[i].getCorrectNumber()' instead
so you want to tell him that the correct is `questions[i].getCorrectNumber()' but you don't know where the value of `questions[i].getCorrectNumber()' is stored
¿is that your problem?