/// Geoff Hagopian PPP exercise 2\

/********
2. If we define the median of a sequence as “a number so that exactly as many elements come
before it in the sequence as come after it,” fix the program in §4.6.3 so that it always prints out
a median. Hint: A median need not be an element of the sequence.
********************/

///
/// This is example code from Chapter 4.6.3 "A text example" of
/// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
///

#include "..\std_lib_facilities.h"

///------------------------------------------------------------------------------

/// simple dictionary: list of sorted words:
int main()
{
    vector<double> temps;        // temperatures
    double temp;
    while (cin>>temp)            // read
        temps.push_back(temp);   // put into vector

    // compute mean temperature:
    double sum = 0;
    for (int i = 0; i< temps.size(); ++i) sum += temps[i];
    cout << "Average temperature: " << sum/temps.size() << endl;

    // compute median temperature:
    sort(temps.begin(),temps.end()); // sort temps
    // "from the beginning to the end."
    cout << "Median temperature: "
         << (temps[temps.size()/2]+temps[temps.size()/2-1])/2 << endl;
}
\

//------------------------------------------------------------------------------
