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 ()

{
	ifstream leaderboard ("E:\\filename");
	int howmany, i;
	double number, lowest, highest,sum=0,score; 
	
	leaderboard >> howmany;
	leaderboard >> number  ;
	sum = number;

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

		if ( score < number)
		{
			score = lowest;
		}
		
		
	}
	
	cout << "average score is: "<<(sum- (highest+lowest))/(howmany-2)<<endl;
	

	
	return (0);
}

Recommended Answers

All 2 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.