Pointers and Arrays Question

I dont know why the average is not popping up it says 0.00 i still can't find a mistake or what i did wrong. Can i get help?

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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
  // Chapter 9, Programming Challenge 2: Test Scores #1
//Gerardo Martinez
//Computer Science
//11/25/14
//***************************************************************
#include <iostream>
#include <iomanip>
using namespace std;

// Function prototypes
void sort(double*, int);
double average(double*, int);

int main()
{
	int numTestScores;    // The number of test scores
	double *testScorePtr; // To point to an array
	double testAverage;   // The test score average

	// Get the number of test scores.
	cout << "\nHow many test scores will you enter? ";
	cin >> numTestScores;

	// Validate the input.
	while (numTestScores < 0)
	{
		cout << "The umber cannot be negative.\n";
		cout << "Enter another number: ";
		cin >> numTestScores;
	}

	// Allocate an array to hold the test scores.
	testScorePtr = new double[numTestScores];

	// ******
	// ADD CODE HERE TO FILL IN THE ARRAY WITH TEST SCORES
	// DO NOT ALLOW SCORES LESS THAN 0
	// *******
	for (int count = 0; count < numTestScores; count++)
{
        cout << "\nEnter The test score for test # " << (count + 1) << ": ";
        cin >> testScorePtr[numTestScores];

        while (testScorePtr[numTestScores] < 0)
	{
		cout << "The umber cannot be negative.\n";
		cout << "Enter another number: ";
		cin >> numTestScores;
	}
}


	// Sort the test scores.
	sort(testScorePtr, numTestScores);

	// Get the average of the test scores.
	testAverage = average(testScorePtr, numTestScores );

	//*** ADD CODE HERE TO OUTPUT THE SORTED SCORES
	// AND THE AVERAGE
	// ***
	cout << "The average of all tests without the lowest test drop: " << testAverage ;

	// Free the dynamically-allocated memory.
	delete [] testScorePtr;
	testScorePtr = 0;

	return 0;
}

// ********************************************************
// The sort function performs a selection sort on the     *
// array pointed to by the score parameter into ascending *
// order. The size parameter holds the number of elements.*
// Selection sort is described in Chapter 8               *
// ********************************************************
void sort(double* score, int size)
{
	int startScan, minIndex;
	double minValue;

	for (startScan = 0; startScan < (size - 1); startScan++)
	{
		minIndex = startScan;
		minValue = *(score+startScan);

		for(int index = startScan + 1; index < size; index++)
		{
			if (*(score+index) < minValue)
			{
				minValue = *(score+index);
				minIndex = index;
			}
		}

		*(score+minIndex) = *(score+startScan);
		*(score+startScan) = minValue;
	}
}

// ********************************************************
// Write the average function to calculate and return the *
// average of the values stored in the array passed in as *
// a parameter. The number of elements in the array is    *
// the second parameter			                  *
// ********************************************************

double average(double *score, int size)
{

    double total = 0.00;
    int totalAverage;
	cout << fixed << showpoint << setprecision(2);

	for (int count = 0; count < size; count++)
        {
        total += *score;
        score++;

        totalAverage = total / size;

        }
        return totalAverage;
}
Line 42, 44: Use count as index instead of numTestScores.
Topic archived. No new replies allowed.