Calculate Body Mass Index - C++ Data Type

C++ examples for Data Type:double

Introduction

The formulas for calculating BMI are


             weight In Pounds *  703 
BMI    =  -------------------------------------
           height In Inches *  height In Inches 

or

               weight In Kilograms 
BMI    =  -------------------------------------
           height In Meters * height In Meters 

Demo Code

#include <iomanip>
#include <iostream>

#define BMI(w, h) ((w * 703) / (h * h))/*from   w  w  w  . j  ava 2  s . c o  m*/

void print_BMI_info();

int main(int argc, const char *argv[]) {
    double weight, height;

    std::cout << "Enter you weight in pounds: ";
    std::cin >> weight;

    std::cout << "Enter your height in inches: ";
    std::cin >> height;

    std::cout << std::setprecision(2) << std::fixed
              << "\nBMI: " << BMI(weight, height) << std::endl;

    print_BMI_info();

    return 0;
}
void print_BMI_info() {
    std::cout << "Underweight: less than 18.5" << std::endl;
    std::cout << "Normal:      between 18.5 and 24.9" << std::endl;
    std::cout << "Overweight:  between 25 and 29.9" << std::endl;
    std::cout << "Obese:       30 or greater\n" << std::endl;
}

Result


Related Tutorials