BMI and BMR calculations, whitespace issue

Making a code to take mass in lbs or kr, height in cm of feet and inches (' and " ), age in years and sex(m or f as there is a set number of 5 and -161 respectively for the calculations.) All is well for the most part but i cannot put a space between number and the unit. For example , 222lbs or 6'0" will work but 222 lbs or 180 cm will not work due to the space. How can i correct this, ive heard getline function or something like that may work but i cannot figure out how to use it in my code. Any help to correct the problem of spaces would be appreciated.

Bill

here is the code so far
_________________________________________________________________

# include <iostream>
# include <string>
using namespace std;

double bmRate(double ma, double h, double a, double sex);
double bmIndex(double ma, double h);

int main(){
string mass,height, hFeet, hInches;
double a;
char sex;
double ma, h,s;
cout<<"Enter weight [in kg or lbs]:";
cin>> mass;
cout<< "Enter height [in cm or in ']: ";
cin>>height;
cout<<"Enter age [in years]:";
cin>>a;
cout<<" Enter sex[ m or f]:";
cin>> sex;

int posM = mass.find("lbs");
int posH= height.find("'");

ma= atof(mass.c_str());

if(posM>0){
ma=ma*0.4535923;
}

if(posH>0){
double len=height.length();
hFeet= height.substr(0,posH);
hInches=height.substr(posH+1.0,len);
double feet=atof(hFeet.c_str());
double inches=atof(hInches.c_str());
h=(inches*2.54)+(feet*12*2.54);
}
else{
h=atof(height.c_str());
}

if(sex=='m'){
s=5.0;
}
if(sex=='f'){
s=-161.0;
}

cout <<"Calculating for " << ma<< " kg and " <<h<<" cm."<<endl;
cout <<"Estimated BMR: "<<bmRate(ma,h,a,s)<<" kcal/day."<<endl;
cout<<"Estimated BMI: "<<bmIndex(ma,h);


}

double bmRate(double ma, double h, double a, double s){
return 10.0*ma+6.25*h+5.0*a+s;
}

double bmIndex(double ma, double h){
return ma/((h/100)*(h/100));
}
Topic archived. No new replies allowed.