Greetings all I need help with a simple C++ Program. Driver\'s License Exam The
ID: 3641355 • Letter: G
Question
Greetings all I need help with a simple C++ Program.
Driver's License Exam
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
2. D
3. A
4. A
5. C
6. A
7. B
8. A
9. C
10. D
11. B
12. C
13. D
14. A
15. D
16. C
17. C
18. B
19. 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, and the answers 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. (Student must have 15 correct out of 20 to pass) 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.
Input Validation: Allow the user to enter answers in either lower or upper case letters. That is, users can enter either A or a.
Thanks in Advance!
Explanation / Answer
Here ya go!
#include <cstdlib>
#include <iostream>
using namespace std;
int main () {
char answers[20] = {'B','D','A','A','C','A','B','A','C','D','B','C','D','A','D','C','C','B','D','A'};
char user_answers[20] = {};
int wrong_answers[20] = {};
int correct = 0;
int incorrect = 0;
for(int i = 0; i < 20; i++) {
wrong_answers[i] = '';
}
for(int i = 0; i < 20; i++) {
char temp;
cout << "Enter the answer to #" << i+1 << ": ";
cin >> temp;
user_answers[i] = toupper(temp);
}
for(int i = 0; i < 20; i++) {
if(answers[i] == user_answers[i]) {
correct++;
}
else if(answers[i] != user_answers[i]) {
wrong_answers[incorrect] = i + 1;incorrect++;
}
}
cout << "Number of correct answers: " << correct << endl;
cout << "Number of incorrect answers: " << incorrect << endl;
cout << "Incorrect answers: ";
for(int i = 0; i < incorrect; i++) {
cout << "#" << wrong_answers[i] << " ";
}
cout << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.