Splat Space - Durham's Hackerspace Message Board › New to programming...

New to programming...

A former member
Post #: 20
#include <cstdlib>
#include <iostream>
#include <std_lib_facilities.h>

int main()
{
vector<double>temps(3);
temps.push_back(76.5);
temps.push_back(73.5);
temps.push_back(71.0);

double temp=0;
double sum=0;
double high_temp=0;
double low_temp=0;

while(cin>>temp)
temps.push_back(temp);

for(int i=0; i<temps.size(); ++i)
{
if(temps>high_temp) high_temp=temps;
if(temps<low_temp) low_temp=temps;
sum+=temps;
}

cout<<"High temperature: "<<high_temp<<endl;
cout<<"Low temperature: "<<low_temp<<endl;
cout<<"Average temperature: "<<sum/temps.size()<<endl;­
keep_window_open();
return 0;
}


why can't I get this vector to work like its supposed to?
Powered by mvnForum

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy