I'm new to this site and a beginner in C++ programming so I'm still learning. I modify my program so that the lowest test score is drop and this score should not be included in the calculation of the average. Any help is deeply appreciated.
This is the part I modify in the program and I'm getting errors in this part:
Code:
int min;
int nn=0;
for (int count = 0; count < numScores; count++)
{
total += scores[count];
if(count==0)min=scores[count];
else if(scores[count]<min)
{
min=scores[count]; nn=1;
}
else if(scores == min)nn++;
}
This is the whole program:
Code:
#include <iostream>
#include <iomanip>
using namespace std;
void arrSelectSort(double[], int);
void showArrPtr(double[], int);
int main()
{
double *scores, // To dynamically allocate an array
total = 0.0, // Accumulator
average; // To hold average scores
int numScores; //Counter variable
cout << "How many test scores would you like to enter? ";
cin >> numScores;
// Dynamically allocate large array to hold test number.
scores = new double[numScores];
// Get the test scores
cout << "Enter the test scores below.\n";
for (int count = 0; count < numScores; count++)
{
cout << "Score " << (count + 1) << ": ";
cin >> scores[count];
if (scores[count] < 0)
{
cout << " \nNegative test values are not possible.\n";
cout << "Please run the program again and enter a positive integer.\n";
while (scores[count] < 0);
}
}
// Calculate the total of the scores
int min;
int nn=0;
for (int count = 0; count < numScores; count++)
{
total += scores[count];
if(count==0)min=scores[count];
else if(scores[count]<min)
{
min=scores[count]; nn=1;
}
else if(scores == min)nn++;
}
// Calculate the average score.
average = total / numScores;
// Display the results.
cout << fixed << showpoint << setprecision(2);
cout << "Average Score: " << average << endl;
// Display the donations using the array of pointers. This
// will display them in sorted order.
cout << "The scores are sorted in ascending order: \n";
arrSelectSort(scores, numScores);
showArrPtr(scores, numScores);
// Free dynamically allocated memory
delete [] scores;
scores = 0;
cout << endl;
system("PAUSE");
return 0;
}
void arrSelectSort(double array[], int size)
{
int startScan, minIndex;
double minElem;
for (startScan = 0; startScan < (size - 1); startScan++)
{
minIndex = startScan;
minElem = array[startScan];
for (int index = startScan + 1; index < size; index++)
{
if (array[index] < minElem)
{
minElem = array[index];
minIndex = index;
}
}
array[minIndex] = array[startScan];
array[startScan] = minElem;
}
}
void showArrPtr(double array[], int size)
{
for (int count = 0; count < size; count++)
cout << array[count] << " ";
cout << endl;
}