Program17

Hello,

I can`t get this code compile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

//compute mean and median temperatures

int main()

{

   vector<double>temps;                     // temperatures
   for (double temp;cin>>temp;)             // read into temp
       temps.push_back(temp);               

//compute mean temperature:

 
   double sum=0;
   for (int x : temps) sum +=x;
   cout<< "Average temperature: "<<sum/temps.size()<< '\n';

//compute median temperature:

sort(temps);           //sort temperatures
cout<< "Median temperature: "<<temps[temps.size()/2]<< '\n';

}

  


I already use the c++11 option
So what is the problem? Do you get some kind of compiler error messages? If so it would help if you posted the complete error message (all of them),.

I fixed line 27:

sort (temps.begin(), temps.end());
Topic archived. No new replies allowed.