### Counting correct answers from 2 arrays

Hi, i'm writing a program that will grade quizzes from a fixed array of correct answers, it compares this array with a text file containing student answers that reads into an array. So i have looped these 2 arrays through each other but now i need to count the correct answers that i find and compute the quiz %. This is what i have so far. Any help would be appreciated

double calculatePercentage(const string key[11],const string stdntAnswers[11], const int SIZE = 11)
{

for (int i = 0; i<SIZE; ++i)
{
{
cout << endl;
}
else
{
cout << "INCORRECT" << endl;
}
}
How would you compute the sum of array values?
Same principle applies to counting.
I would do something like sum+=arrayname[] within a for loop.
could you give me a rough example of what counting would look like?
 I would do something like sum+=arrayname[]

Beware of mixing apples and oranges. `sum` one assumes is an integer. `arrayname[]` is not clear, but it might be supposed to be a string. You wouldn't want to add a string to an integer. Don't mix apples and oranges.

 could you give me a rough example of what counting would look like?

You have an example of counting in your own code:`++i`. `++i` (or `i++` or` i = i + 1`) simply adds 1 to a variable.

The variable `i` is used to count the iterations of the loop. It does that by adding 1 to the variable each time an iteration is completed.

You would need to use a different variable. Set it to zero before you begin. Add 1 to it each time you find something that you are counting, whether it be a sheep or a loop iteration or a correct answer.

When there are no more sheep or answers to be counted, the final value of your variable is the total.

(Sorry about the references to sheep - I wanted to make this a general rather than a specific answer, and "counting sheep" was the first thing which came to mind).

Last edited on
Topic archived. No new replies allowed.