Question about test scores program w/ pointers

closed account (3UMLy60M)
Hello all,

I have created a program that allows for a user-defined number of test scores as input. After the user enters these scores, the program calculates the average test score. Here is my code:

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
#include <iostream>
#include <iomanip>
using namespace std;

// Function prototypes
double getAverage(double*, int);

int main()
{
	// Variable declarations
    double *testScores;	// Dynamically allocate an array of test scores
    double average;	    // Hold the average test score
    int numTests;		// Number of test scores
    int count;     		// Counter variable

    	// Get the number of tests
    	cout << "How many tests do you wish to process? ";
    	cin >> numTests;
    
    	// Verify input is not a negative number
    	while (numTests <= 0)
    	{
			// Get input again.
        	cout << "Please enter a positive number:  ";
        	cin >> numTests;
    	}

    	// Dynamically allocate an array large enough to hold the test scores
    	testScores = new double[numTests];

    	// Get the specified number of test scores
    	cout << "Enter the test scores below.\n";
    	for (count = 0; count < numTests; count++)
    	{
    		cout << "Test " << (count + 1) << ": ";
    		cin >> *(testScores + count);
        
        	// Verify input is not a negative number
       		while (*(testScores + count) < 0)
        	{
        		// Get input again.
            	cout << "Please enter a valid test score.\n";
            	cin >> *(testScores + count);
        	}
    	}

    	// Calculate the average test score
    	average = getAverage(testScores, numTests);

    	// Display the results.
    	cout << fixed << showpoint << setprecision(2);
		cout << endl;
    	cout << "The average of those scores is:  " << average << endl;

    	// Free dynamically allocated memory
    	delete [] testScores;
    	testScores = 0;		// Make testScores point to null
		return 0;
} 

//function getAverage - calculates the average of the test scores
double getAverage(double* scores, int num)
{
	double avg;
    double total = 0.0;
	for (int count = 0; count < num; count++)
	{
		total += scores[count];
	}
    avg = total / num;
	return avg;
}

I am having trouble with the final part of my program. How do I pass the array of test scores to a function that calculates how many people got an A (90+) on the test? The final output should look like this:

The average of those scores is:
The number of A grades is:

Any help would be appreciated.

Thanks!
You were able to pass it to `getAverage()' ¿don't you?
closed account (3UMLy60M)
Yes, but how do I create a function that can determine exactly how many of the scores were above 90?
Topic archived. No new replies allowed.