///Geoff Hagopian
///checking math summation formulas

#include "std_lib_facilities.h"

///conversion takes any unit and converts to the standard m
double convert(double x, string s) {
    const double inches_per_meter = 0.0254;
    if(s=="m")
        return x;
    if(s=="in")
        return x*inches_per_meter;
    if(s=="cm")
        return x/100;
    if(s=="ft")
        return x*0.3048;
    else
        error("Sorry, I don't know that unit");
}


int main() {
    /**7. Add a unit to each double entered; that is, enter values
    such as 10cm, 2.5in, 5ft, or 3.33m. Accept the four units:
    cm, m, in, ft. Assume conversion factors 1m == 100cm,
    1in == 2.54cm, 1ft == 12in. Read the unit indicator into a string.
    You may consider 12 m (with a space between the number and the unit)
     equivalent to 12m (without a space).**/

    double x, minD, maxD;
    double meters;
    string unit;
    vector<double> vDouble;
    vector<string> vUnit;
    cout << "\nEnter a double and the units of the double:\n";
    cin>>x;
    cin>>unit;
    vDouble.push_back(x);   ///prime the pump
    vUnit.push_back(unit);
    minD = convert(x,unit);
    maxD = minD;
    cout << "\nEnter a double and the units of the double:\n";
    while(cin>>x) {
        vDouble.push_back(x);
        cin >> unit;
        vUnit.push_back(unit);
        meters = convert(x,unit);
        for(int i=0;i<vDouble.size()-1;i++) {

            if(meters>maxD) maxD = meters;
            if(meters<minD) minD = meters;
        }
        cout << setprecision(16) << "\nYou entered "
             << x << unit;
        if(meters==maxD) cout << ", the largest so far.\n";
        else if(meters==minD) cout << ", the smallest so far.\n";
        else cout << endl;

    }
}
