I have to drop the lowest score, and i can't include it in the calculation of the average. for input validation cant accept negative numbers for test score.
#include <iostream>
#include <iomanip>
using namespace std;
void arrSelectSort(float *, int);
void showArrPtr(float *, int);
void showAverage(float, int);
int main()
{
float *scores, //To dynamically allocate an array
total=0.0; //Accumulator
float lowest;
int numScores; //To hold the number of test scores
//Get the number of test scores.
cout << "How many test scores would you like to process? ";
cin >> numScores;
//Dynamically allocate an array large enough to hold that many
//test scores
scores = new float[numScores];
if(scores==NULL)
return 0;
//Get the test score for each test
cout << "Enter the test scores below.\n";
for (int count = 0; count < numScores; count++)
{
cout << "Test score #" << ( count + 1 ) << ": ";
cin >> scores[count];
//Validate the input.
while (scores < 0)
{
cout << "Zero or negative numbers not accepted.\n";
cout << "Test Score #" << (count + 1) << ": ";
cin >>scores[count];
}
}
//Calculate the total scores
for (int count = 0; count < numScores; count++)
{
total += scores[count];
}
//sort the elements of the array pointers
arrSelectSort ( scores, numScores );
//Will display them in sorted order.
cout << "The test scores in ascending order are: \n";
showArrPtr ( scores, numScores );
showAverage( total, numScores );
//Get lowest
lowest = scores[0];
for ( int count = 1; count < numScores; count++)
{
if(scores[numScores] < lowest)
lowest = scores[numScores];
}
//Free memory.
delete [] scores;
return 0;
}
void arrSelectSort(float *array, int size)
{
int startScan, minIndex;
float 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(float *array, int size)
{
for (int count=0; count< size; count++)
cout << array[count] << " ";
cout << endl;
}
void showAverage(float total, int numScores)
{
float average;
//Calculate the average
average = (total - lowest) / (numScores - 1);
//Display the results.
cout << fixed << showpoint << setprecision(2);
cout << "When dropping lowest score the average is: " << average << endl;
}
I don't really know how not to include it in the calculation, or if someone could give me a hint as to how to drop a test score without including it in calculation. there is nothing in this chapter or past ones that talks about doing something like this .but the way i did it it should work, execpt it tells me that lowest is an undiclared indentifier in the void showAverage part. Also when i remove this part my input validation wont work properly, actually it doesn't work at all. Why is that is no different from how i had written it before.