I'm teaching myself through Programming: Principles and Practice Using C++ (2nd Edition) and I'm at the vectors section. I can copy and paste their code and it still won't work. My code is as follows.
#include "iostream"
#include "vector"
#include "algorithm"
using namespace std;
int main()
{
cout << "Please enter the temperatures for the last five days\n";
vector<double> temperatures;
for(double temp; cin >> temp;){
temperatures.push_back(temp);
}
double sum = 0;
for (double temp : temperatures){
sum += temp;
}
cout << "Mean temperature is " <<(sum / temperatures.size()) << endl;
sort(temperatures);
cout << "Median temperature is " << temperatures[temperatures.size()/2];
}
Help is appreciated and an explanation is better.
std::sort
properly.