1. Okay, now I have the right lowest and highest (the couts for them is debugging code) but the average is still wrong.
Code:
```#include <iostream>
#include <iomanip>
using namespace std;
int main( ) {
float n;
float average = 0;
float o;
float value = 0;
float highest = 0;
float lowest = 0;
float oth = value;
//  cin >> o;
n = 7;
cin >> oth;
highest = oth;
lowest = oth;
for (float i = 1; i < n; ++i) {
//   highest = value;
// lowest = value;
cin >> value;

if (value > highest) {
highest = value;
}
if (value < lowest) {
lowest = value;
}

average += value;

}
cout << highest << endl;
cout << lowest << endl;
if (value != highest || value != lowest) {
average /= 5;
}
// average = average + 1;
cout << "Average score: " << setprecision(3) << average;
}``` 2. Any help? 3. Your if statement is all mangled now. You are saying if value isn't highest or lowest then calculate the average. So if your last value input is the highest or lowest you won't even average.

At this point you aren't taking the values out that you don't want. So your average after the loop equals the sum of ALL values. You have the correct value of lowest and highest but you need to remove the sum of the two from your average before executing.

Make sure to remove that if statement because it doesn't do what you think it does.

You are very close though. 4. Okay, I now get 7.7 instead of 7.82 with 9.2,4.3,6,8.7,7.3,8.0,and 9.1.
Code:
```#include <iostream>
#include <iomanip>
using namespace std;
int main( ) {
float n;
float average = 0;
float o;
float value = 0;
float highest = 0;
float lowest = 0;
float oth = value;
//  cin >> o;
n = 7;
cin >> oth;
highest = oth;
lowest = oth;
for (float i = 1; i < n; ++i) {
//   highest = value;
// lowest = value;
cin >> value;

if (value > highest) {
highest = value;
}
if (value < lowest) {
lowest = value;
}

average += value;

}
//cout << highest << endl;
//cout << lowest << endl;
//   if (value != highest || value != lowest) {
average = average - highest + lowest;
average /= 5;
//}
// average = average + 1;
cout << "Average score: " << setprecision(3) << average;
}``` 5. Code:
`average = average - highest + lowest;`
Think about that for a second. C++ handles the operator order of addition and subtraction from left to right so you aren't getting the value you think you are. Just in numerical terms think about how it would evaluate.

10 - 4 + 5

So it would execute 10-4 and be 6 then add 5 to six so you would end up with 11.

A set of parenthesis could completely change that.

10 - (4 + 5)

Now you will get 4+5 executed first which is 9 then that will be subtracted from 10 and you will get 1. 6. Still not working:
Code:
```#include <iostream>
#include <iomanip>
using namespace std;
int main( ) {
float n;
float average = 0;
float o;
float value = 0;
float highest = 0;
float lowest = 0;
float oth = value;
//  cin >> o;
n = 7;
cin >> oth;
highest = oth;
lowest = oth;
for (float i = 1; i < n; ++i) {
//   highest = value;
// lowest = value;
cin >> value;

if (value > highest) {
highest = value;
}
if (value < lowest) {
lowest = value;
}

average += value;

}
cout << highest << endl;
cout << lowest << endl;
//   if (value != highest || value != lowest) {
average = average - (highest + lowest);
average /= 5;
//}
// average = average + 1;
cout << "Average score: " << setprecision(3) << average;
}``` 7. Solved  8. Congratulations xD 9. Now that it's solved, I guess I can show this:
Code:
```#include <istream>
#include <limits>
#include <algorithm>

float jck::FindAverage(std::istream& input) {
long count = 0L;
float sum = 0.0;
float highest = std::numeric_limits<float>::min();
float lowest = std::numeric_limits<float>::max();
float value;

while (input >> value) {
highest = std::max<float>(value, highest);
lowest = std::min<float>(value, lowest);
sum += value;
++count;
}

return (sum - highest - lowest) / (count - 2L);
}```
Just showing what's possible. You can do a lot in a few lines if you just stop and think. ... And use a few functions to simplify logic (even if you have to make your own). 10. Originally Posted by whiteflags Now that it's solved, I guess I can show this:
Code:
```#include <istream>
#include <limits>
#include <algorithm>

float jck::FindAverage(std::istream& input, const int& repitition) {
long count = 0L;
float sum = 0.0;
float highest = std::numeric_limits<float>::min();
float lowest = std::numeric_limits<float>::max();
float value;

while (input >> value) {
highest = std::max<float>(value, highest);
lowest = std::min<float>(value, lowest);
sum += value;
if( ++count > repetition - 1 )
{
break; //?
}
}

return (sum - highest - lowest) / (count - 2L);
}```
Just showing what's possible. You can do a lot in a few lines if you just stop and think. ... And use a few functions to simplify logic (even if you have to make your own).
What stops the loop? 11. End of file. That is how the function is designed to know when to stop.

Or a read error. I'd throw an exception of some sort instead of returning if that could happen, I suppose. There are a lot of reasonable responses and it still would depend on the programmer's needs. Popular pages Recent additions 