Problem with Arrays Assignment

The local Driver’s License Office has asked you to write a program that grades the written portion of the driver’s license exam. The exam has 20 multiple choice questions. Here are the correct answers:

1. B 6. A 11. B 16. C
2. D 7. B 12. C 17. C
3. A 8. A 13. D 18. B
4. A 9. C 14. A 19. D
5. C 10. D 15. D 20. A

Your program should store the correct answers shown above in an array. It should ask the user to enter the student’s answers for each of the 20 questions, which should be stored in another array. After the student’s answers have been entered, the program should display a message indicating whether the student passed or failed the exam. (A student must correctly answer 15 of the 20 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the question numbers of the incorrectly answered questions.


I got this far, but I want to know how to make it not case-sensitive, so if the person enters "a" instead of "A" it'll still register the same answer.

My code looks like this so far:

#include <iostream>
#include <cctype>

using namespace std;

void checkAnswers(char[], char[], int, int);


int main() {
const int NUM_QUESTIONS = 20;
const int MIN_CORRECT = 15;
char answers[NUM_QUESTIONS] = {
'B', 'D', 'A', 'A', 'C',
'A', 'B', 'A', 'C', 'D',
'B', 'C', 'D', 'A', 'D',
'C', 'C', 'B', 'D', 'A'
};

char stu_answers[NUM_QUESTIONS];

//Loop for users answers
for (int replies = 0; replies < NUM_QUESTIONS; replies++) {
cout<< "Please enter your answers: "
<< (replies + 1) << ": ";
cin >> stu_answers[replies];

//Validation of users answers
while (stu_answers[replies] != 'A' && stu_answers[replies] != 'B' && stu_answers[replies] != 'C' && stu_answers[replies] != 'D') {
cout << "You must enter A, B, C, or D\n";

cout<< "Please enter your answers: "
<< (replies + 1) << ": ";
cin >> stu_answers[replies];
}

}

checkAnswers(answers, stu_answers, NUM_QUESTIONS, MIN_CORRECT);

return 0;
}

void checkAnswers(char answers1[], char stu_answers1[], int NUM_QUESTIONS, int MIN_CORRECT) {
//cout << "max: " << NUM_QUESTIONS;
int correctAnswers = 0;

//Check the student's replies against the correct answers
for (int i = 0; i < NUM_QUESTIONS; i++) {
if (answers1[i] == stu_answers1[i])
correctAnswers++;
}
//Did they pass or fail?
cout << "\nYou must have at least 15 correct to pass.";
if (correctAnswers >= MIN_CORRECT) {
cout << "\nStudent passed the exam\n\n";
}
else {
cout <<"\nStudent failed the exam\n\n";
}

//Display a list of the questions that were incorrectly answered.
cout << "The list below shows the question numbers of the incorrectly";
cout << " answered questions.\n";
for (int i = 0; i < NUM_QUESTIONS; i++) {
if (answers1[i] != stu_answers1[i])
cout << "Question # " << i << " is incorrect." << endl;
}

//Display the number of correct and incorrect answers provided by the student.
cout << "\nCorrect Answers = " << correctAnswers << endl;
cout << "Incorrect Answers = " << NUM_QUESTIONS - correctAnswers << endl;
}


Thank you!
Topic archived. No new replies allowed.