The assignment: Write a program that grades the written portion of the driver\'s
ID: 3619772 • Letter: T
Question
The assignment: Write a program that grades the written portion of the driver's license exam. The exam has 20 multiple choice questions (answers input into code already. Your program should store the student's answers for each of 20 questions in an array, the answers 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). It should 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: only accept A, B, C or D as answers. Here's my code: #include <iostream>using namespace std;
/* This Driver's License Exam program will grade the written portion of the driver's license exam.
The program will store the correct answers to 20 multiple choice questions and once the student answers
have been entered, grade the exam. */
int main()
{
// Define variables
int count, // counter variable for loops
correct=0, // variable to count the number of correct answers input by student
inCorrect=0; // stores the amount of incorrectly answered questions
const int size = 20; // constant variable for max size (there will be 20 spots in array)
char studentAnsw[size]; // studentAnsw array stores student input
// store answers to multiple choice questions in storedCorrectAnswer array
char storedCorrectAnsw[size] = {'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D',
'B', 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A'};
// Allow student to input answers, store in studentAnsw Array
cout << "Please enter your answers to the multiple choice questions by inputting A, B, C, or D. Upper case only." << endl;
// if statement for input validation to go into loop must be A B C or D
if(studentAnsw[size]!='A'||'B'||'C'||'D')
{
cout << "Please input A, B, C or D for your answer, all upper case." << endl;
cin >> studentAnsw[size];
}
if(studentAnsw[size]=='A'||'B'||'C'||'D')
{
// for loop to match storedCorrectAnswer array against studentAnswer array and tally correct answers
for (count=0; count<=size-1; count++)
{
cout << "Enter the answer for Question " << (count+1) << ": ";
cin >> studentAnsw[count];
}
if (storedCorrectAnsw[count] == studentAnsw[count])
correct+=1;
if (storedCorrectAnsw[count] != studentAnsw[count])
inCorrect+=1;
}
// Display whether student passed of failed.
if(correct>=15)
{
cout << "Congratulations! You passed the Driver's Exam with " << correct << " out of 20 questions correct." << endl;
}
else
{
cout << "Unfortunately you did not pass the exam. You only had " << correct << " out of 20 questions correct." << endl;
}
// pause
system("pause");
return 0;
}
I'm having 3 problems 3) I'm getting a weird error message associated with my studentAnsw array
Explanation / Answer
please rate - thanks corrections to your code, the red is commented out, the teal has a while loop added and a } removedRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.