# Using an Array to store the count.

• 11-27-2001
Unregistered
Using an Array to store the count.
The basic problem I was given is to write a C++ program to output a report that shows the grade distribution for a course. The program first prompts for and inputs the specified number of students. The program then prompts for and inputs the final grade for each student.
Finally the program displays a report of the grade distribution.The hint given was There is no need to use an array to store the actual input grades, instead use an array to keep track of the counting, that is, how many times each grade occurs in the input.

I can manage the input on number of students, but the hint throws me off course.
I'm guessing I should have an array of size 9
But I have no Idea on how to keep track of number of times students get different grades.
This is my second week using C++, and I've only used arrays to hold the input.
Any help or more usefull hints would be apreciated.
• 11-28-2001
zen
If you have grades 1->5 then you could create an integer array with five elements, and increment it for each grade -

```#include <iostream.h> int main() {     int num_students  = 0;     int grade = 0;     int grade_scale[5] = {0}  // A, B, C, D, F     char letter_grade[5] = {'A', 'B', 'C', 'D', 'F'};     cin >> num_students;     for ( int i = 0; i < num_students; i++)     {         cin >> grade;         if ( grade > 89 )             ++grade_scale[0];  // add an A         else if ( grade > 79)             ++grade_scale[1];  // add a B         else if ( grade > 79)             ++grade_scale[2];  // add a C         else if ( grade > 79)             ++grade_scale[3];  // add a D         else             ++grade_scale[4];  // add an F     } // end for loop     for ( i = 0; i < 5; i++)         cout << letter_grade[i] << ":  " << grade_scale[i] << endl;     return 0; } // end main```