How to exclude numbers from an equation?

For example I used an array to get 5 test scores from a user and then I have to find the average excluding the highest test score along with the lowest test score. What should I use to exclude the highest and lowest score. Thanks!
One way is to first sort the array. Then you know that you should skip the first and last score in the array.
My code is as follows:

#include <iostream>
#include <string>
using namespace std;

int main()
{
string name;
string pnumber;
double scores[5];
double avg = 0.0;
double highest = 0.0, lowest= 0.0;
int i;

cout << "What is your name? ";
getline(cin, name);

cout <<"What is your phone number? ";
cin >> pnumber;

cout << "\nPlease enter your scores: ";
cin >> scores[0];

lowest=highest=scores[0]; // set highest and lowest to first score
for (i=1;i<5; i++)
{
cout << "\nPlease enter your scores: ";
cin >> scores[i];
if(scores[i]>highest)
highest=scores[i];
if(scores[i] < lowest)
lowest=scores[i];
}
//you need to include score[0] in the average

avg = (scores[0]+scores[1]+scores[2]+scores[3]+scores[4])/5;
cout <<"The average score is " << avg << endl;
cout << "The highest score is " << highest << endl;
cout << " The lowest score is " << lowest;

return 0;
}



What would be the next step if I am trying to figure out how to exclude the highest and lowest?
You already have highest and lowest so this is just simple math problem. You can calculate the value you are looking for with just basic mathematical operations and the variables avg, highest and lowest.
Got it! it was simple but I didn't know, now I do thanks!
Topic archived. No new replies allowed.