Adding to Array

I'm trying to get this program to output how many grades are above or equal to the average and how many are below the average.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    #include <iostream>
    using namespace std;
    int main()
    {
    
    float grade[10]; // 10 array slots
    int count;
    float total = 0; 
    double average; 
    for (count = 1; count <= 10; count++)
    {
    cout << "Enter grade " << count << ": ";
    {
    cin >> grade[count]; 
    } 
    } 
    
    //printing the grades entered to be display on screen again.
    cout << "You have entered the following grades: " << endl;
    for(count = 1; count <= 10; count++) 
    total = total + grade[count];
    average = total/10;
    cout << "Your average of ten grades are: " << average << endl; //Output of average
    
    system ("pause");
    return 0;
    
    }
Last edited on
1
2
float grade[10]; // 10 array slots
                           // numbered 0 to 9 


for (count = 1; count <= 10; count++) //10 is out of bounds

You need to get used to dealing with arrays that start at zero, this is the idiom for doing something 10 times:

1
2
3
for (count = 0; count < 10; count++) {  //do it 10 times

}


Hope this helps
Last edited on
Thank you for your feedback, however, I'm trying to find out how to get the program to output how many grades are above or equal to the average and how many are below the average.
So you have an array with grades in it, and you have an average value- can you figure out how to do it?
Topic archived. No new replies allowed.