Hello
mkory,
Next time use the code tags ([_code] and [_\code]--remove the "_") so that this is easier to read. May you elaborate on what issues you are getting? Maybe some sample input and sample output?
I believe that your mistake is that you are updating your min and max constantly within your inner loop. This needs to happen only once per judging round.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
using namespace std;
int main( void ){
int id, numjudge;
double max,min,avg,scorecount=0;
double score[10];
cout<<"Hello this program will calculate average score for an athelete"<<endl<<endl;
cout<<"In order to stop the program enter a negative value for ID"<<endl<<endl;
cout<<"enter ID of an athlete"<<endl;
cin>>id;
while (id>=0){
cout<<"now enter the the number of judges judging the contest"<<endl;
cin>>numjudge;
cout<<"now enter the score of each judge"<<endl;
min=999999999; /* Enter some arbitrarily large number */
max=0; /* Enter some arbitarily low number */
for (int i=0;i<numjudge;i++){
cin>>score[i];
for (int k=0;k<10;k++){
/* You updated your max and min to score[0].*/
if(score[i]>max){
max=score[i];
}else if (score[i]<min){
min=score[i];
}
}
scorecount=scorecount+score[i]; /* scorecount += score[i]; */
}
avg=(scorecount-min-max)/(numjudge);
cout<<"average for the athlete is "<<avg<<endl;
cout<<"enter the id of the next athlete"<<endl;
cin>>id;
}
return 0;
}
|
Recommendations:
1. Add an exception prevention on that numjudge command, because if the user enters 11 you will go out of the bounds of your array.
2. It seems a bit strange for you to re-define how many judges you want every time you input a new id. I would recommend doing this only at the beginning of the program once. However, I don't know your requirements, so take that with a grain of salt.
3. What happens if your max or min are repeated? e.g. 5 judges enter a score of 10. Shoud all of them be removed? Or just one?
4. You need to handle the case where there is only one judge. If there is only one judge, you will end up with a negative score. I don't know if you want this behavior or if you would prefer 0 being the minimum score.
In short: Consider all of your test cases. These may be contributing to the incorrect answer issue.