Storing the result

Dear everyone, I have an assignment to count the number of students who scored 'x' marks in GQ quiz, which I believe I have solved, and store the result in the array sum_gq[]. How to store the value? For the last aspect of the assignment I have a question how to write the latter aspect as a C++ command? Thank you!

Short introduction:
int numOfStudents: Integer number containing the total number of students
int gq[]: Integer array containing the GQ marks of all students
int sum_gq[]: Integer array to be computed

Here's the code I wrote so far:
1
2
3
4
5
void getTotalGQ(int numOfStudents, int gq[], int sum_gq[]) {
for (i=0; i<numOfStudents; i++)
   while (gq[i] == x) { count++; }
sum_gq[x] = count; //is this valid?
}
why do you have an array sum_gq[] to store a single value (the count of x)?

is this valid?
Only if x is within the bounds of the array sum_gq[].

Change your code to:
1
2
3
4
void getTotalGQ(int numOfStudents, int gq[], int sum_gq[]) {
for (i=0; i<numOfStudents; i++)
   if (gq[i] == x) { sum_gq[x]++; } // where does x come from?
}
It is because I was asked by the question to do so. Thank you.
Topic archived. No new replies allowed.