Can someone help me with this problem. I cannot figure out how to get the max and min in this array.When I execute the program it gives me incorrect numbers for high and low. It reads from a file: Iget 3.00 for high and low
diver1.txt
9.2
9.3
9.0
9.9
9.5
9.5
9.6
9.8
Add code to do the following:
format the output to two decimal places
print out the high score
print put the low score
print out the sum after high score and low score are dropped (calculate the sum, subtract the high, subtract the low. )
double findmax ( double x[], int sizeX);
double findmin ( double x[], int sizeX);
int main()
{
string filename ; // name of the input fi
ifstream inFile; //input file stream variable
double divingScore [ARRAY_SIZE] ;
cout << "Enter the name of the input file: " ;
cin >> filename;
inFile.open(filename.c_str () );
if (!inFile)
{
cout << "bummer file name \n\n";
system ("pause");
return 1;
}
fillArray (inFile, divingScore,ARRAY_SIZE ) ;
double x = findmax(divingScore,ARRAY_SIZE);
double y = findmin(divingScore,ARRAY_SIZE);
cout << "The scores are :\n";
cout << fixed << showpoint << endl;
cout << setprecision (2);
printList ( divingScore,ARRAY_SIZE);
cout << "High score is: ";
cout << x << endl;
cout << "Low score is: ";
cout << y << endl;
system ("pause");
return 0;
}
//Function to print the elements of an int array.
//The array to be printed and the number of elements
//are passed as parameters. The parameter listSize
//specifies the number of elements to be printed.
void printList(const double list[], int listSize)
{
int index;
cout <<endl ;
for (index = 0; index < listSize; index++)
cout << list[index] << endl;
}
//inputs numbers from inFile; listSize tells the number of
// scores to input. Assumes that the file was opened by the caller.
void fillArray (ifstream& inFile, double list[], int listSize)
{
int sub ;
sub = 0;
while ( sub < listSize )
{
inFile >> list [ sub];
sub++;
}
}
double findmax ( double list[], int listSize)
{
int sub;
int maxsub = 0;
for ( sub = 1; sub < listSize; sub++)
if (list[maxsub] <= list[sub])
maxsub = sub;
return maxsub;
}
double findmin ( double list[], int listSize)
{
int sub;
int minsub = 9999;
for ( sub = 1; sub < listSize; sub++)