Please help. I can't figure out what I am doing wrong. Here is the assignment plus the code that I have so far. It's not doing what I want it to do.
Create a C++ program that takes six test scores as input and stores them in an array. It drops the lowest score, and computes the average of the remaining five scores. It outputs the average score.
#include <iostream>
#include <iomanip>
using namespace std;
//Function Prototype
int LowestScore ( int *GradeArray, int );
//Constants
const int SIZE = 6;
int main()
{
int Total, index, LowestIndex;
double Average;
int GradeArray[SIZE] = {0};
//Requests 6 test scores
cout << "Please enter 6 test scores" << endl << endl;
//Populates the arrays
for ( int index = 0; index < SIZE; index++)
{
cout << "Please enter score " << index << ": ";
cin >> GradeArray[index];
//cout << endl;
}
/*
LowestIndex = 0;
LowestScore( GradeArray, LowestIndex ); //Function call
Total = 0;
//This loops adds up all of the scores except the lowest one.
for ( index = 0; index < SIZE; index++)
{
//This statement will skip adding the lowest index
if ( GradeArray[ index ] == GradeArray[ LowestIndex ] )
{
index++;
}
//Adds up all scores except the lowest one
else
{
Total += GradeArray[ index ];
index++;
}
}
*/
Total = 0;
//Finds the average of the 5 remaining and then displays the answer
cout << fixed << showpoint << setprecision( 1 );
Average = Total / 5;
cout << "Your test average: " << Average << endl;
return 0;
}
//This function finds the lowest score
int LowestScore ( int *GradeArray, int LowestIndex )
{
int index;
//This loops finds the lowest score by comparing each score
for( index = 0; index < SIZE; index++ )
{
if ( GradeArray[ index ] < GradeArray[ LowestIndex ] )
{
LowestIndex = index;
}
}
1) Use [code] tags.
2) State what behavior you're getting.
3) State what behavior you're expecting.
Also, you're prototype at first glance looks fine. Using the syntax suggested by soranz is looked down upon for various reasons. Here's some proof that it works: http://codepad.org/GsqtY42i
for ( index = 0; index < SIZE; index++)
{
if ( GradeArray[ index ] == GradeArray[ LowestIndex ] )
{
continue;
}
else
{
Total += GradeArray[ index ];
}
}