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!
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.