#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
/***************************************************************************************************
*
* @params: none
*
* @descript: Asks inputs from the user ( weight, height, age, and sex ) with the desired number of unites
* then the program does the required work( such as conversion from one unit to another )
* to calculate for BMR and BMI.
*
* @returns: 0 for succession.
*
***************************************************************************************************/
int main()
{
string weight, height;
float age;
int indexWeight, indexHeight;
char sex;
string mass, massUnits, height1, height2, heightUnits1, heightUnits2;
float myValueofMass, myValueofWeight;
float heightValue, heightValue2, myValueofHeight1, myValueOfHeight2, myValueofHeight2, myValueofHeight, BMR, BMI;
cout << "\nEnter mass: [in kg orlbs ]";
getline ( cin, weight );
indexWeight = weight.find ( ' ', 0 ); // index depends on the number of digits that the user provided
mass = weight.substr (0, indexWeight );
massUnits = weight.substr ( indexWeight + 1);
myValueofMass = atof ( mass.c_str () );
if ( massUnits == "lbs" ){
myValueofWeight = myValueofMass*0.4535923; // 0.4535923 is the conversion factor for lbs to kg
}
cout << "\nEnter height: [in cm or with the unit of inch]:";
getline ( cin, height );
indexHeight = height.find ( ' ', 0 );
height1 = height.substr ( 0, indexHeight );
// height2 = height.substr ( 0, );
heightUnits1 = height.substr ( indexHeight + 1 );
heightUnits2 = height.substr ( indexHeight + 2 );
myValueofHeight1 = atof ( height1.c_str() );
myValueofHeight2 = atof ( height2.c_str() );
if ( heightUnits1 == " ' " ){
heightValue = myValueofHeight1*30.48;
}
if ( heightUnits2 == " \" "){
heightValue2 = myValueOfHeight2*2.54;
}
myValueofHeight = heightValue + heightValue2;
cout << "\nAge: [ in years ]:";
cin >> age;
cout << "\nSex: [m or f]";\
cin >> sex;
if (sex == 'm'){
sex = 5;
}
else{
sex = -161;
}
BMR = 6.25*myValueofHeight + 10.0*myValueofWeight + 5.0*age + sex;
BMI = myValueofWeight /(myValueofHeight*myValueofHeight);
cout << "\nCalculating for " << weight << " and " << height;
cout << "\nEstimated BMR: " << BMR << "kcal/day" << endl;
cout << "Estimated BMI: " << BMI << endl;
return 0;
}