Need Some Help; Comparing Array?

Writing code to determine how correct a student was on a True/False test...
I can't for the life of me figure out how to compare the two char arrays and come up with the right answer for returning the amount of correct answers the student gave. Can someone give me some help?
Last edited on
The problem is not your checking of the correct answers, but where you're doing it.

You call inputStudentData once. For each student, you're storing into studentAnswer overwriting the previous student's answers. When you call processData at line 21, you have only the results of the last student in studentAnswer.

BTW, it's not a good idea to use the same index variable in two nested for loops (lines 57-58). What you have is not illegal, but if you wanted to reference the outter loop variable inside the inner loop, you would not be able to do so.

Other problems:
Line 27: The backslash characters are escape characters. \( and \) are not valid escape sequences. If you want to use \ as a printable character in a literal, you must double them.

Line 2: You need a #include <string>

Oooh. Haha oh man. I see what I did but I'm not sure how to fix it, how do I call the function based on the number of students without overwriting?

I'm in a basic C++ class and this is the only assignment I'm struggling to understand. :/
You have two choices.
1) You could make studentAnswer a two dimensional array:
 
char studentAnswer[SIZE_OF_CLASS][SIZE_OF_TEST];

You'd need to adjust your logic to deal with the two dimensions.

2) You could move your call to processData to after line 49. That way you would process the current student before going on to the next one.

Oh my god you're a life saver! Didn't realize that putting my function call in other functions was a viable option. Such a noob... lol. Thanks again!
Shoot, I have another problem. When I enter the student's answers, everything works fine. However I have another problem. When calculating the percentage, only getting 100% seems to want to work.

At the end when it displays the percentage, getting any number of questions wrong other than 10 will result in 0%. What's going on? I tried putting percentage as an int and as a double but neither works.
Last edited on
Line 32: answersCorrect and SIZE_OF_TEST are both integers, so you're doing integer division. 9/10=0. Cast answersCorrect to a double before doing the divison.

 
percentage = ((double)answersCorrect / SIZE_OF_TEST) * 100;

Ahh, I checked everything but my answersCorrect variable type. So much I gotta learn here. Thanks!!!
Topic archived. No new replies allowed.