/* Assignment 2 Question 2 (Calculate BMI)
	Name: Tan Ming Hui (A20EC0155)
	Name: Kalaivani A/P Subramaniam (A20EC0056)
	Date: 2020/12/25 */
	
#include <iostream>
#include <iomanip> // to use setprecision
#include<cstring> // to use strcmp
using namespace std;

double getBMI(double weight, double height) 
{
	return (weight) / (height* height); // return based on formula bmi
} 

string getStatus(double BMI)
{
	if (BMI > 30)
		return "Obese";
	else if (BMI >25)
		return "Overweight";
	else if (BMI >= 18.5)
		return "Normal";
	else 
		return "Underweight";
}

void Output(string name, double weight, double height, double BMI, string status)
{
	cout<<fixed<<setprecision(2);
	cout << "\nName 	: " << name << endl;
	cout << "Weight	: " << weight << " kilograms" << endl;
	cout << "Height	: " << height << " meters" << endl;
	cout << "BMI	: " << BMI << endl;
	cout << "Status	: " << status << endl;
}

string Finalstatus(double OverallBMI)
{
	if (OverallBMI > 30)
		return "Obese";
	else if (OverallBMI >25)
		return "Overweight";
	else if (OverallBMI >= 18.5)
		return "Normal";
	else 
		return "Underweight";
}

int main()
{
	// declaration for all variable used
	char name[50];
	double weight, height, BMI, OverallBMI, totweight = 0, totheight = 0; // totweight is totalweight, totheight is totalheight
	string status, overallstatus;
	int i=0; // for counting the number of people's data enter
	
	cout << "Enter name or press <ENTER> key to end=> ";
	cin.getline(name, 50);
	
	while(strcmp(name,""))
	{
		cout << "Enter weight (kg) and height (m) =>  ";
		cin >> weight >> height;
		
		// send data to respective function to process
		BMI = getBMI(weight,height);
		status = getStatus(BMI);
		Output(name, weight, height, BMI, status);
		
		// update 
		totweight = totweight + weight;
		totheight = totheight + height;
		i=i+1;
	
		cin.ignore();	
		cout << "\nEnter name or press <ENTER> key to end=> ";
		cin.getline(name,50);
	}
	
	OverallBMI = ((totweight/i)/((totheight/i)*(totheight/i)));
	
	overallstatus = Finalstatus(OverallBMI);
	
	cout << "\nOverall BMI : " << OverallBMI << endl;
	cout << "Overall Status : " << overallstatus << endl;

	return 0;
}




