So this is my assignment and i am so close to finishing it i just keep getting some errors.
The local Driver's license office has asked you to write a program that grades the written portion of the drivers license exam.
Here is my coding. I am getting the right answers for most of the test cases except for the missing coding that i have to do. But when i put in the correct answers it says i missed 18 and got 2 correct.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int num_correct = 0;
int num_missed = 0;
const int SIZE = 21;
char your_answers[SIZE];
char correct_answers[SIZE] = {'B','D','A','A','C'
,'A','B','A','C','D',
'B','C','D','A','D',
'C','C','B','D','A'};
cout << " Drivers License Exam Grader" << endl;
for (int count = 1; count < SIZE; count++)
{
cout << "Enter your answer for question " << count << endl;
cin >> your_answers[count];
if (correct_answers[count] == your_answers[count])
{
num_correct++;
}
else
{
num_missed++;
}
if (your_answers[count] != 'A' && your_answers[count] != 'B' && your_answers[count] != 'C' && your_answers[count] != 'D')
{
cout << "Invalid Input. Enter only: A, B, C, OR D. Try again." << endl;
count--;
num_missed--;
}
}
I suppose you could make another for loop for that, but why bother when you already have one that you can use? :)
Now, if you wanted to put the ones you got wrong below the results, then yes, you'd need another for loop for that. You'd just have to go through and recheck all of the answers, but instead of counting up the ones you got right or wrong, you just print it out if it's wrong.