hello,
ok this code works fine but it still dosnt compute the avearage with the lowest score dropped.
here is my code.
CODE
#include <iostream>
#include <iomanip>
using namespace std;
void sortArray( double arr[], int sz, int scoresPos[], int size );
void displayArray( double arr[], int sz, int scoresPos[], int size );
int main()
{
double *scores, total = 0; // average;
int count;
int numAmount;
cout << "How many test scores are you going to record? ";
cin >> numAmount;
scores = new double[numAmount];
int *scorePos = new int[numAmount];
cout << "Please enter in your test scores below.\n";
for ( count = 0; count < numAmount; count++ )
{
cout << "Test Score " << (count + 1) << ": ";
cin >> scores[count];
scorePos[count] = count + 1;
}
sortArray( scores, numAmount, scorePos, numAmount );
displayArray( scores, numAmount, scorePos, numAmount );
delete [] scores;
delete [] scorePos;
return 0;
}
//************************************************** *********************
// Definition of a sortArray *
// This function excepts a double array and its size as an *
// argument. The results will be diplayed in ascending order *
//************************************************** *********************
void sortArray( double arr[], int sz, int scoresPos[], int size )
{
double temp = 0;
int posTemp = 0;
for ( int i = 0; i < sz - 1; i++ )
{
for ( int j = ( i + 1 ); j < sz; j++ )
{
if ( arr[i] > arr[j] )
{
temp = arr[i];
posTemp = scoresPos[i];
arr[i] = arr[j];
scoresPos[i] = scoresPos[j];
arr[j] = temp;
scoresPos[j] = posTemp;
}
}
}
}
//************************************************** ***********************
// Definition of a display array *
// This function excepts array and its size as an argument. The *
// average will be displayed dropping the lowest score. *
//************************************************** ***********************
void displayArray( double arr[], int sz, int scoresPos[], int size )
{
double average = 0;
double sum = 0;
std::cout << std::endl; // for spacing
for ( int i = 0; i < sz; i++ )
{
cout << "Score " << scoresPos[i] << " : ";
cout << arr[i] << std::endl;
}
int j;
for ( j = 1; j < sz; j++ )
{
sum += arr[j];
}
average = sum / j;
cout << "\nThe average score disregarding the lowest score is: " << average << endl;
cout << fixed << showpoint << setprecision(2);
}