so im stuck

Basically I have burned out my brain doing 4 other problems just fine and I have no idea what so ever how to begin or even do this problem.


Write a function that reads in 10 grades and determines how many are above or equal to the average and how many are below. Read in the grades in main(), call the function to do the calculation, and print out the entire array so you can verify the result. in C++
Think of the problem as a set of smaller sub-problems.

Pseudo-code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// declare variables
array or vector to store grades
total grade
average grade
count of how many are above or equal to average
count of how many are below average

// input
ask user to input 10 grades	and store it in array					// you can use a for/while loop
	in that loop add the grade to the total							// compound operator (+=)

// calculate the average
average = total / 10

use a loop to filter thru the array
	if grade is greater than or equal to average
		increment count of above or equal to average
	else
		increment count of below average
	while you're looping through the array
	you may as well print it out 
Last edited on
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <iomanip>
using namespace std;



double get_average(double *scores, const int iElements)
{
    double total = 0.0;
    //Calculate the total of the scores
    for (int count = 0; count < iElements; count++) {
        total += scores[count];
    }
    
    return total / iElements;
}

int get_geavg(double *scores, const int& iElements, double& dblAvg)
{
    int ge = 0;
    for (int i = 0; i < iElements; i++) {
        if (scores[i] >= dblAvg) ++ge;
    }
    return ge;
}




int main ()
{
    double *scores,	//To dynamically allocate an array
    total = 0.0,
    average;
    int numScores,
    count,
    greater = 0, // number of results greater or equal average
    less = 0; // number of results less than average
    
    //Get the number of test scores
    cout << "How many test scores would you like to enter? ";
    cin >> numScores;
    
    //Dynamically allocate an array large enough to hold that many test scores
    
    scores = new double[numScores];
    
    //Get the test scores
    cout << "Enter the test scores below.\n";
    for (count = 0; count < numScores; count++)
    {
        cout << "Test Score " << (count + 1) << ": ";
        cin >> scores[count];
    }
    
    
    average = get_average(scores, numScores);
    
    
    int above_average = get_geavg(scores, numScores, average);
    
    
    //Display the results
    
    
    cout << fixed << showpoint << setprecision(2);
    cout << " Average score is: " << average << endl;
    cout << "Above Average scores: " << above_average << endl;
    cout << "Below Average scores: " << numScores - above_average << endl; 
    
    
    
    
    //Free dynamically allocated memory
    delete [] scores; 
    
    return 0; 
}



this is what i have so far
Last edited on
Please wrap your code in the appropriate tags.
http://www.cplusplus.com/articles/jEywvCM9/

I've tested out the code and it seems to be working fine.
Good work :)

Last edited on
Topic archived. No new replies allowed.