Question: I am getting an error here, what am i doing wrong? #include #include using namespace std; int grade(char correctAnswers[], char studentAnswers[], int size); // start

I am getting an error here, what am i doing wrong?

#include

#include

using namespace std;

int grade(char correctAnswers[], char studentAnswers[], int size);

// start main

int main()

{

// constant declaration

const int maxQuestions = 10;

// arrays declaration

char correctAnswers[maxQuestions] = { 'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D' };

char studentAnswers[maxQuestions];

// variables declaration

int correctCount = 0, invalidCount = 0;

char answer;

bool passed;

for (int i = 0; i < maxQuestions; i++)

{

// prompt the user to enter the answer

cout << "Enter the answer for the question #" << (i + 1) << ": ";

cin >> answer;

// verify whether the student answer is valid

while (answer != 'A' && answer != 'B' && answer != 'C' && answer != 'D')

{

// count the invalid answers

invalidCount++;

// exit from the program if the invalid answers > 3

if (invalidCount > 3)

{

cout << "GOOD BYE" << endl;

exit(1);

}

// prompt the user to enter valid answer

cout << "Please enter A, B, C, or D only: ";

cin >> answer;

}

// store the answer in the studentAnswers array

studentAnswers[i] = answer;

}

// call the grade function to get the student correct answers

correctCount = grade(correctAnswers, studentAnswers, maxQuestions);

// verify whether the student has passed the exam

if (correctCount >= 8)

{

// if student passed

cout << " Congratulations!" << endl;

cout << "You have passed exam." << endl;

cout << "Total number of correct answers: " << correctCount << endl;

cout << "Total number of incorrect answers: " << (maxQuestions - correctCount) << endl;

}

else

{

// if student failed

cout << " Sorry, you have not passed the exam!" << endl;

cout << "Total number of correct answers: " << correctCount << endl;

cout << "Total number of incorrect answers: " << (maxQuestions - correctCount) << endl;

}

cout << endl;

return 0;

} // end of main function

// grade function implementation

int grade(char correctAnswers[], char studentAnswers[], int size)

{

int correctCount = 0;

for (int i = 0; i < size; i++)

{

if (correctAnswers[i] == studentAnswers[i])

{

correctCount++;

}

}

return correctCount;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!