I have to compute the olympic average(removing highest and lowest score and then taking the average of what's left) using a for loop and if statements. I can get the lowest value out, but I can't get the highest. Here's what I have so far:

``````//       ,CMPSC  ,   olympic average

#include <iostream>
#include <fstream>

using namespace std;

int main ()

{
int howmany, i;
double number, lowest, highest,sum=0,score;

sum = number;

for (i=2; i<= 10; i++)
{
sum += score;

if ( score < number)
{
score = lowest;
}

}

cout << "average score is: "<<(sum- (highest+lowest))/(howmany-2)<<endl;

return (0);
}``````
3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by WaltP

Think out the algorithm first. You want to remove the lowest and highest values, so first read all values into an array, determining the high/low values as you go and adding up the number of items read. When you are done, iterate through the array, adding up all but the high/low numbers and divide the resulting value by the number read (-2) to get your olympic average. From what I can see, you aren't doing that...

Where do you deal with the highest value? I only see lowest.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.