i have to write a program that(prompt the user to enter them one at a time) an unspecified number of temperatures in Celcius from the keyboard. Add each value to a vector created using the STL with the push_back function. Instruct the user to enter an invalid temperature (<-273) to indicate that they are done entering values. Use STL functions and algorithms to find the max, min, sum, and count (number of values) and display the results.Also sort the temperatures in increasing order and display the values.
while(degrees < -273)
{
cout << "Enter the temperature values: ";
cin >> degrees;
temps.push_back(degrees);
}
iter = max_element(temps.begin(),temps.end());
cout << "The max temperature is: " << *iter << endl;
//sum = accumulate (temps.begin(),temps.end(),0);
//cout << "The sum of the temperatures is: " << sum << endl;
accumulate is a template that synthesizes its return type from the type of its last parameter.
You are passing an int (0). Therefore, the function is attempting to return int. But your
iterators are iterators to doubles, so somewhere in there it is adding together an int and
a double and storing the result in an int.
sum = accumulate( temps.begin(), temps.end(), 0.0 );