# BMI Calculator using C++ language | Ultimate Guide

Eiman.pk has uploaded a detailed guide on how to build Body Mass Index (BMI) calculator using C++ language.

## Body Mass Index (BMI)

Formula of BMI Calculator is

BMI = Weight in kilograms / Height in meter square

BMI classification system that is used by the World Health Organization (WHO):

• BMI less than 18.5: Underweight
• BMI 18.5 to 24.9: Normal weight
• BMI 25.0 to 29.9: Overweight
• BMI 30.0 or greater: Obese

## Which Compiler is best?

• For Laptop, Offline or PC Devices use Visual Studio Code or CFree
• For Mobile Devices you can use online Compilers such as w3shools.

## Code Elements:

To build a body mass index (BMI) calculator using C++ language we will need the following elements of C++ language.

### <iostream> Library

iostream library is an object-oriented library which provides us with input and output functionality using streams in C++ language.

### <math.h> Library

We are going to use <math.h> library because we perform calculations and mathematical operations in our BMI calculator.

### cout command

We will use cout commands to print our output on the screen.

### cin command

in command will be used to collect data such as weight and height from the user.

### if else condition

If else condition is used to show the different results of the calculation.

## Final Coding:

We have divided the code into segments so that you can understand them better.

### Library :

1- First we will write the library and namespace.

#include <iostream>
#include <math.h>
using namespace std;
int main () {
}

### Declaring Variables:

2- Then we will declare the variables.

double weight_kilogram, height_msquare;

We are using kilogram for our weight and meter square for our height.

### Collecting Data:

If we want to collect data from the user then we will use cin in out code as follow

  cout << "Enter your weight in Kilograms: \n";
cin >> weight_kilogram;

cout << "Enter your height in meter square: \n";
cin >> height_msquare;

### Formula code of BMI:

The most important part of BMI calculator is applying the formula as follow:

double bmi = (weight_kilogram)/((height_msquare)*(height_msquare));


### Cout the output:

   cout<<"Your BMI is ";
cout<<bmi;