c++ trouble, I cant figure the rest of the code out.

This is what I'm working on. I got some of the code but it don't seem to work right. I dont know how to sort the array out to subtract the highest and lowest numbers.
In the sport of diving, seven judges award a score between 0 and 10, where each score may be a floating-point value. The highest and lowest scores are thrown out and the remaining scores are added together. The sum is then multiplied by the degree of difficulty for that dive. The degree of difficulty ranges from 1.2 to 3.8 points. The total is then multiplied by 0.6 to determine the diver’s score.

Write a computer program that inputs a degree of difficulty and seven judges’ scores, and outputs the overall score for that dive. The program should ensure that all inputs are within the allowable data ranges. To make your programming easier, if a number is out of range (greater than the upper limit or less than the lower limit), then let the program replace it with upper or lower limit numbers.

Hint: Use double Array and for loop statement
Hint: Use highest variable with the initial value of 0, and lowest variable with the initial value of 10, in order to find out the highest and the lowest values.


*** sample output

Please enter the difficulty level(1.2 - 3.8): 1
Enter the score of judge 1: 5
Enter the score of judge 2: 4
Enter the score of judge 3: 3
Enter the score of judge 4: 2
Enter the score of judge 5: 1
Enter the score of judge 6: 6
Enter the score of judge 7: 7

Scores = { 5 4 3 2 1 6 7 }
Difficulty level = 1.2
Total score = 14.4



This is what I got so far.

#include <iostream>
#include <algorithm>

using namespace std;
double score;

int main(){
float difficulty;

double highlow, subtotal, totalscore;

cout<<"Please enter the difficulty level {1.2-3.8): " <<endl;
cin >> difficulty;

double score[7];
cout << "Enter the score of judge 1: " <<endl;
cin >> score[0];

cout << "Enter the score of judge 2: " <<endl;
cin >> score[1];

cout << "Enter the score of judge 3: " <<endl;
cin >> score[2];

cout << "Enter the score of judge 4: " <<endl;
cin >> score[3];

cout << "Enter the score of judge 5: " <<endl;
cin >> score[4];

cout << "Enter the score of judge 6: " <<endl;
cin >> score[5];

cout << "Enter the score of judge 7: " <<endl;
cin >> score[6];

{for (int i=0;i<7;i++)

cout << "Scores = {"<< score[i] << "}" <<" ";
cout << "\n";
system ("pause");}

std::sort(score, score+7);


highlow = score[0]+=score[6];
subtotal = score[7] -= highlow;
totalscore= subtotal*=0.6;
cout << "Total Score = " << totalscore << endl;

return 0;
system ("pause");
}
std::sort(score, score+7);

I don't think that std::sort works like this. You should use a syntax like:

1
2
3
vector<double> vscore(score, score+7); //intialize a vector with your array
vector<double>::iterator it; //declare an iterator
sort (vscore.begin(), vscore.end()); //sort the values. 


Now you can calculate the sum of sorted values minus the two extremes:
1
2
3
4
double sum;
vector<double>::size_type sz = vscore.size();
  for (i=1; i<sz-1; i++) 
     sum +=  vscore[i];


You can then multiply with the
(degree of difficulty)*0.6
and be done with it
Pointers are random access iterators. http://cplusplus.com/reference/std/iterator/iterator_traits/
So you can use std::sort(score, score+size);

1
2
highlow = score[0]+=score[6];
subtotal = score[7] -= highlow;
¿what are you doing there?
Topic archived. No new replies allowed.