// MUHAMMAD NAZRI IZZAT BIN HAMDAN A20EC0216 //
// RAJA MUHAMMAD HAFIZ BIN RAJA ALAUDIN SHAH A20EC0223 //
// 25.12.2020 //

#include <iostream>
#include <cmath>
using namespace std;

void getBMI(float *bmi, float w, float h);
string getStatus(float bmi);

int main()
{
    string name, status, ovrl_status;
    float w, h, bmi, ovrl_bmi, ovrl_w, ovrl_h, avg_bmi, avg_w, avg_h;
    int counter, n;

    counter = 0;
    ovrl_bmi = 0;
    ovrl_h = 0;
    ovrl_w = 0;

    cout << "Please enter number of people." << endl;
    cin >> n;

do
{
    cout << "\nEnter name: ";
    cin >> name;
    cout << "Enter weight(kg): ";
    cin >> w;
    cout << "Enter height(m): ";
    cin >> h;

    getBMI(&bmi, w, h);

    ovrl_h = ovrl_h + h;
    ovrl_w = ovrl_w + w;

    status = getStatus(bmi);

    cout << "\nName" << "\t" << ":" << name << endl;
    cout << "Weight" << "\t" << ":" << w << " Kilograms" << endl;
    cout << "Height" << "\t" << ":" << h << " Meters" << endl;
    cout << "BMI" << "\t" << ":" << bmi << endl;
    cout << "Status" << "\t" << ":" << status << endl;

    counter++;
}
while (counter < n);

avg_h = ovrl_h/n;
avg_w = ovrl_w/n;
ovrl_bmi = avg_w/pow(avg_h, 2.0);

if (ovrl_bmi > 30.0)
    {
        ovrl_status = "Obese";
    }
    else if (ovrl_bmi > 25.0)
    {
        ovrl_status = "Overweight";
    }
    else if (ovrl_bmi > 18.5)
    {
        ovrl_status = "Normal";
    }
    else
    {
        ovrl_status = "Underweight";
    }

cout << "\nOverall BMI : " << ovrl_bmi << endl;
cout << "Overall Status :" << ovrl_status << endl;

return 0;
}

void getBMI(float *bmi, float w, float h)
{
    *bmi = w/(pow(h,2));
}

string getStatus(float bmi)
{
    if (bmi > 30.0)
    {
         return "Obese";
    }
    else if (bmi > 25.0)
    {
        return "Overweight";
    }
    else if (bmi > 18.5)
    {
        return "Normal";
    }
    else
    {
        return "Underweight";
    }
}
