need help with this program

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--;
}
}


cout << "Results (minimum 15 correct to pass): "<< endl;
cout << "You got " << num_correct << " correct" << endl;
cout << "You missed " << num_missed << endl;
if (num_correct >= 15)
{
cout << "You've passed!" << endl;
}
else if(num_correct < 15 && num_correct >= 0)
{
cout << "You've failed."<< endl;
}
}

then i can't figure out how to make a loop to get the result below for all the wrong answers

Answer 1 is incorrect.
Answer 16 is incorrect.
Answer 17 is incorrect.
Answer 18 is incorrect.
Answer 19 is incorrect.
Answer 20 is incorrect.
Your for loop starts at int count = 1, but array indices start at 0, so all of your answers are getting inputted one question off.

Also, why is SIZE 21 and not 20?
You only have 20 elements in that array.

If you want it to say which ones you got wrong, put it in the else part of your if (correct_answers[count] == your_answers[count]) check.
the reason that size is 21 is cause i need the array to start at question 1
can i do the ones i got wrong in a for loop

and how would i go about that if possible also how would u suggest the else in the if statement (correct_answers[count] == your_answers[count])
Last edited on
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.
I need to output which questions i got wrong after the answer loop. but then i also need to count up the ones i got wrong in the result section
Changes
for (int count = 1; count < SIZE; count++)
to
for (int count = 0; count < SIZE-1; count++)

and

cout << "Enter your answer for question " << count << endl;
to
cout << "Enter your answer for question " << count+1 << endl;
Last edited on
ok that helps me with how to get the questions to line up right but i still am unsure how to program the wrong question output
i was thinking of writting a for loop as so

for (count = 0; count < variable(unsure which variable to use); count++)
{
cout << "Answer " count << " is incorrect." << endl;
}

im not sure if that would get my result im looking for.

Answer 1 is incorrect.
Answer 16 is incorrect.
Answer 17 is incorrect.
Answer 18 is incorrect.
Answer 19 is incorrect.
Answer 20 is incorrect.

but this output has to be the questions that i get wrong so im not sure if the above loop will get the result that is why i am asking for help
Topic archived. No new replies allowed.