Vectors and cout not working...thanks.

I am new to programming, so I am sure this is all messed up. I am trying to learn about vectors, and in this code I am trying to get the medium and average temp, but I cannot get a anything to anything to show up. The code for the cout is not working.

Thanks for you help in advance.

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
vector<double> temps;
for (double temp; cin>>temp;)
temps.push_back(temp);

{
double sum = 0;
for (double x: temps) sum += x;
cout <<"Average temperature:" << sum/temps.size() << '\n';
sort (temps.begin(), temps.end());
cout << "Median temperature: " << temps[temps.size()/2] << '\n';


}

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

}

return 0;
}
That what I get:
1
2
3
4
5
10 20 30 40^Z
Average temperature:25
Median temperature: 30
Average temperature: 25
Press any key to continue . . .


You need to end your input with ctrl+z or F6
Last edited on
Thomas1965 - thank you very much. That helps a lot. Thanks.
Topic archived. No new replies allowed.