1. ## Need help writing......

A program that reads in 7 float numbers and outputs the average, with the exception of the highest and lowest numbers.
What I currently have:
Code:
```#include <iostream>
#include <iomanip>
using namespace std;
int main( ) {
float n;
float average;
float o;
float value = 0;

//  cin >> o;
n = 7;
for(float i = 0; i < n; ++i) {
cin >> value;
average += value;
}
average /= n;
cout << "Average score: "; //<< setprecision(3) << average;
}```
The program currently works, but does not do the highest and lowest numbers. Can someone help me figure out how to do that? And if there are any problems with my current program, please let me know. 2. Any help? 3. You don't initialize average. And you haven't bothered to get the lowest or highest inputs for exclusion. 4. Okay, first of all, that code that is commented out should not be. And I need help figuring out the lowest/highest inputs thing. 5. Originally Posted by Kelton2 Okay, first of all, that code that is commented out should not be.
That still leaves average uninitialized. Originally Posted by Kelton2 And I need help figuring out the lowest/highest inputs thing.
If you can't even do that, I recommend you get a good book, or take a good online tutorial series.

But, I'll give you a hint
Code:
```if(value > highest) {
highest = value; }``` 6. Got it:
Code:
```#include <iostream>
#include <iomanip>
using namespace std;
int main( ) {
float n;
float average = 0;
float o;
float value = 0;
float highest = 0;

//  cin >> o;
n = 7;
for(float i = 0; i < n; ++i) {
highest = value;
cin >> value;
if(value > highest) {
highest = value;
}
average += value;
}
average /= n;
cout << "Average score: " << setprecision(3) << average;
}```
Now I need the lowest, and more importantly how to make it exclude the highest and lowest 7. Any help? I got the lowest condition, just need to make it affect the output. 8. Nobody? I really need help. My code with the lowest condition is:
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;

//  cin >> o;
n = 7;
for(float i = 0; i < n; ++i) {
highest = value;
lowest = value;
cin >> value;
if(value > highest) {
highest = value;
}
if(value < lowest) {
lowest = value;
}
average += value;
}
average /= n;
cout << "Average score: " << setprecision(3) << average;
}``` 9. It almost works now, but still not quite.
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;

//  cin >> o;
n = 7;
for(float i = 0; i < n; ++i) {
highest = value;
lowest = value;
cin >> value;
if(value > highest) {
highest = value;
}
if(value < lowest) {
lowest = value;
}
if(value != highest || lowest) {
average += value;
}
}
average /= n;
average = average + 1;
cout << "Average score: " << setprecision(3) << average;
}``` 10. Originally Posted by Kelton2 Code:
`             if(value != highest || lowest)`
does not do what you think it does. What you have written is identical to
Code:
`if(value != highest || lowest != 0)` 11. So how do I fix it? 12. Now I have:
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;

//  cin >> o;
n = 7;
for(float i = 0; i < n; ++i) {
highest = value;
lowest = value;
cin >> value;
if(value > highest) {
highest = value;
}
if(value < lowest) {
lowest = value;
}
if(value != highest || value != lowest) {
average += value;
}
}
average /= n;
// average = average + 1;
cout << "Average score: " << setprecision(3) << average;
}```
Still doesn't work... 13. You solve this by going back to pen and paper. If you don't understand the problem, then you can't solve it. 14. I understand the problem. To average numbers, you add all the numbers together and then divide that by the amount of numbers. I need to exclude the highest and lowest numbers, you get the highest by setting the highest to the input number and if a new high is found, setting it to that. Same for lowest, but with new low.
It's just that my implementation is wrong, and I can't understand why. 15. Write down the steps, not an high level idea.
You will then see why it is not working.

Some hints:

Code:
```    highest = value;
lowest = value;```
Why do you do this everytime?

Code:
`if(value != highest || value != lowest)`
If you do this within the loop, you get the 'current' highest or lowest, not the global one.
So, wait for the loop to be done before subtracting the highest and lowest from the sum. Popular pages Recent additions 