For one of my intro to C++ assignments, I must write code where a group of athletes performances is judged by a variable number of judges. The performance score of the athletes is obtained by rejecting both the lowest and the highest score, and taking the average of the remaining scores. I have most of it figured out I think, however the minimum score is a bit over my head; the max score can be reset to 0, for following athletes to be judged, but the minimum cannot, because no score will be less than 0 to be picked up as a low score. My code:
Code:
#include <iostream>
using namespace std;
int main ()
{
int athleteid, numjudges, startjudges, scorecard;
double score, total, average, min, min2, max=0;
cout.setf(ios::fixed,ios::floatfield);
cout.precision (1);
cout << "Welcome to the athlete performance score program" << endl;
cout << "To start, please enter the athlete ID> ";
cin >> athleteid;
while (athleteid > 0)
{
scorecard=1;
cout << "How many judges gave entered a score?> ";
cin >> numjudges;
for (startjudges=1; startjudges <= numjudges; startjudges++)
{
cout << "Please enter score " << scorecard << ">";
cin >> score;
if (score > max)
{
max = score;
}
if (score < min)
{
min = score;
}
total = total+score;
scorecard++;
}
average= (total-(max+min))/(numjudges-2);
cout << "The average is " << average << endl;
total=0;
max=0;
min=(I get stuck here);
cout << "Finished. Enter next athlete ID, 0 to finish> ";
cin >> athleteid;
}
system("pause");
}
Everything works out well for the most part, but I have no clue on how to reset the min variable, to pick up the lowest number again while the loop goes back around.
Any help would be appreciated.