1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #include <cmath>
- #include <iomanip>
- std::string BMI(std::string weight, std::string height) {
-
- float w = std::stof(weight );
- float h = std::stof(height);
-
- if(std::string::npos != weight.find("pounds")){
- w = w * 0.453592;
- }
- if(std::string::npos != height.find("inches")){
- h = h * .0254;
- }
-
- std::string bmi = std::to_string(round(10*(w/(h*h)))/10);
-
- int pos = bmi.find(".");
-
- bmi = bmi.substr(0,pos+2);
- float bmiFloat = round(10*(w/(h*h)))/10;
- if(18.5>bmiFloat){
- return bmi + " Underweight";
- }
- if(24.9>=bmiFloat){
- return bmi + " Normal weight";
- }
- if(29.9>=bmiFloat){
- return bmi + " Overweight";
- }
- if(30<=bmiFloat){
- return bmi + " Obesity";
- }
-
- }
|