This post contains a total of 10+ CPP BMI Calculator Program Examples with Source Code. All these BMI ( Body mass index ) Calculator Programs are made using C++.
You can use the source code of these examples with credits to the original owner.
Related Posts
CPP BMI Calculator Programs
1. BMI calculator usa & international
Made by BroFar. Source
120 5 5 usa weight: 120lbs usa height: 5'5 int weight: 54.48klg int height: 1.625m Normal BMI: 20.6315 Your Normal range 107 to 144 pounds
#include <iostream>
using namespace std;
int main() {
double w; double f;
double i; double bmi;
cin >> w; /* pounds */
cin >> f; /* feet */
cin >> i; /* inches */
int s = f * 12 + i;
double h = (f * 12 + i)/40;
/* ft & in to meters */
/* united states */
cout << "usa weight: " << w << "lbs"<< " \nusa height: " << f << "'" << i << endl;
/* international metric*/
cout << "\nint weight: " << w*0.454 << "klg" << " \nint height: " << h << "m" << endl;
/* convertions */
h *= h;
w *= 0.454;
bmi = (w / h);
if (bmi < 18.5){
cout << "\nUnderweight BMI: " << bmi << endl;
}
else if ((bmi >= 18.5) && (bmi < 25)){
cout << "\nNormal BMI: " << bmi << endl;
}
else if ((bmi >= 25) && (bmi < 30)){
cout << "\nLittle overweight exercise recommended ( check blood pressure and minor health issus ) BMI: " << bmi << endl;
}
else {
cout << "\nOverweight time to exercise and diet ( check for blood pressure, cardiac and lung issues, as well as, other health issues ) BMI: " << bmi << endl;
}
cout << " " << endl;
switch(s){
case 58: case 59:
cout << "Your Normal range 91 to 119 pounds" << endl;
break;
case 60: case 61: case 62:
cout << "Your Normal range 97 to 131 pounds" << endl;
break;
case 63: case 64: case 65:
cout << "Your Normal range 107 to 144 pounds" << endl;
break;
case 66: case 67: case 68:
cout << "Your Normal range 118 to 158 pounds" << endl;
break;
case 69: case 70: case 71:
cout << "Your Normal range 128 to 172 pounds" << endl;
break;
case 72: case 73: case 74:
cout << "Your Normal range 140 to 186 pounds" << endl;
break;
case 75: case 76:
cout << "Your Normal range 152 to 197 pounds" << endl;
break;
}
return 0;
}
2. Simple BMI Calculator
Made by Hatsy Rei. Source
170 50 Your BMI value is 17.301
#include <iostream>
#include <string>
using namespace std;
/*
On the first line, input your height in cm.
On the second line, input your weight in kg. E.g.
170
50
which will output BMI value of 17.301.
*/
int main()
{
float height_cm;
float height_m;
float sqr_height;
float weight_kg;
float BMI_value;
cin >> height_cm;
cin >> weight_kg;
height_m = height_cm / 100.00;
sqr_height = height_m * height_m;
BMI_value = weight_kg / sqr_height;
cout << "Your BMI value is " << BMI_value;
cout << endl;
return 0;
}
3. Simple BMI Calculator ++
Made by Hatsy Rei. BMI calculator with indicative scales. Source
165 50 Your BMI value is 18.4 You are underweight
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
/*
On the first line, input your height in cm.
On the second line, input your weight in kg. E.g.
*/
int main()
{
float height_cm;
float height_m;
float sqr_height;
float weight_kg;
float BMI_value;
cin >> height_cm;
cin >> weight_kg;
height_m = height_cm / 100.00;
sqr_height = height_m * height_m;
BMI_value = weight_kg / sqr_height;
cout << fixed << setprecision(1) << "Your BMI value is " << BMI_value;
cout << endl;
if (BMI_value < 16.5) cout << "You are seriously underweight";
else if (BMI_value < 18.5) cout << "You are underweight";
else if (BMI_value < 25.0) cout << "You are normal";
else if (BMI_value < 30.0) cout << "You are overweight";
else if (BMI_value >= 30.0) cout << "You are obese";
return 0;
}
4. BMI Calculator by Aleksander Szczepura
Made by Aleksander Szczepura. Source
55 165 You weigh 55 kg and your height is 165 cm. Your BMI is equal 20.2. You are healthy.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
void getData(float &w, float &h){
cin>>w>>h;
}
float calcBMi(float w, float h){
return w/(h*h/10000.0);
}
string displayFitnessResults(float bmi){
if(bmi<18.5){
return "You have underweight.";
}else if(bmi>=18.5 && bmi<=24.9){
return "You are healthy.";
}else if(bmi>=25.0 && bmi<=29.9){
return "You have overweight.";
}else{
return "You are obese.";
}
}
int main() {
float weight;
float height;
getData(weight, height);
if(weight<1 || weight> 2345){
cout << "Are you sure you weigh " << weight << " kg?" << endl;
return 1;
}
if(height < 10 || height > 300){
string x = " centimeters?";
if(height > 300){
x = " meters?";
height /= 100;
}
cout << "Are you really tall at "<< setprecision(2) << height << x << endl;
return 2;
}
float bmi = calcBMi(weight, height);
string fat = displayFitnessResults(bmi);
cout << setprecision(3) << "You weigh "<< weight << " kg and your height is " << height << " cm." << endl <<"Your BMI is equal "<< bmi << "." << endl << fat;
return 0;
}
5. BMI calculator in kg and cm
Made by Ana. Source
75 167 Enter your weight in kg and your height in cm Your bmi is26.8923 overweight
#include <iostream>
using namespace std;
int main() {
cout<<"Enter your weight in kg and your height in cm"<<endl;
double cm,kg;
cin>>kg;
cin>>cm;
double bmi;
bmi =kg/(cm*cm)*10000;
cout<<"Your bmi is"<<bmi<<endl;
if (bmi<=18.5)
{cout<<"underweight";}
if (bmi>18.5&&bmi<25)
{cout<<"normal bmi";}
if (bmi>=25)
{cout<<"overweight";}
return 0;
}
6. BMI calculator using cpp
Made by Joseph Lusitche. Source
70 1.67 Your Body Mass Index is:25.7117 You are overweight.
/*For accurate results,please enter your mass(kg) and height(m), respectively ,each on a different line.*/
#include <iostream>
using namespace std;
int main(){
long double mass ;
long double height ;
long double bmi ;
cin >>mass ;
cin>>height ;
bmi =mass /(height *height ) ;
if (bmi <=25){
if (bmi >=18.5){
cout <<"Your Body Mass Index is:" <<bmi <<endl ;
cout <<"You are normal."<<endl ;
}
else {
cout <<"Your Body Mass Index is:" <<bmi<<endl ;
cout <<"You are underweight ."<<endl ;
}
}
else {
if (bmi <=30) {
cout <<"Your Body Mass Index is:" <<bmi<<endl ;
cout <<"You are overweight."<<endl ;
}
else {
cout <<"Your Body Mass Index is:"<<bmi<<endl ;
cout <<"You are obese ." <<endl ;
}
}
return 0;
}
7. BMI Calculator by Saurabh Tiwari
Made by Saurabh Tiwari. Source
1 167 55 BMI=19.721
/*1st enter ur choice
if choice is 1 --> enter ur height in cms and
weight in kgs
if choice is 2 --> enter ur height in inches
(not ft and inches) and weight in lbs
*/
#include <iostream>
using namespace std;
//Compiler version g++ 6.3.0
int main()
{
float ht,wt,ch,bmi;
cin>>ch>>ht>>wt;
if(ch==1)
{
ht=ht/100;
bmi=wt/(ht*ht);
cout<<"BMI="<<bmi;
}
else if(ch==2)
{
ht=ht*2.54/100;
wt=wt*0.4536;
bmi=wt/(ht*ht);
cout<<"BMI="<<bmi;
}
else
cout<<"wrong choice!";
}
8. BMI Calculator by Adeadaccount
Made by Adeadaccount. Source
165 55 Your BMI index is 20.202 You are normal!
#include <iostream>
using namespace std;
int main() {
/*
ATTENTION
Input:
Height: cm
Weight: kg
*/
double height, weight;
cin >> height >> weight;
height /= 100;
if (height < 0 || weight < 0) {
cout << "INVALID INPUT!";
return 0;
}
double bmi = weight/(height*height);
cout << "Your BMI index is " << bmi << endl;
if (bmi < 18.5) {
cout << "You are underweight!";
}
else {
if (bmi < 25) {
cout << "You are normal!";
}
else {
if (bmi < 30) {
cout << "You are overweight!";
}
else {
if (bmi < 35) {
cout << "You are obese!";
}
else {
cout << "You are extremely obese!";
}
}
}
}
return 0;
}
9. BMI Calculator by Marta
Made by Marta. Source
1.5 40 ------------------------------------- Your BMI = 17.78 (Mild Thinness) -------------------------------------
/*
Enter your height [m] and weight [kg].
*/
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double weight, height, bmi;
cin >> height >> weight;
bmi = weight / (height * height);
cout << fixed << setprecision(2);
cout << "-------------------------------------" << endl;
cout << endl;
cout << " Your BMI = " << bmi << " ";
if (bmi < 16.0) cout << "(Severe Thinness)";
else if (bmi < 17.0) cout << "(Moderate Thinness)";
else if (bmi < 18.5) cout << "(Mild Thinness)";
else if (bmi < 25.0) cout << "(Normal)";
else if (bmi < 30.0) cout << "(Overweight)";
else if (bmi < 35.0) cout << "(Obese Class I)";
else if (bmi < 40.0) cout << "(Obese Class II)";
else cout << "(Obese Class III)";
cout << endl;
cout << endl;
cout << "-------------------------------------" << endl;
return 0;
}
10. BMI Calculator (kg,m)
Made by Avaros. Source
Enter your weight: 60 Enter your height: 1.60 BMI value: 23.4375 Normal (healthy weight)
//Remember to use a dot, not a comma in a height//
//Use meters and kilograms//
#include <iostream>
#include <math.h>
using namespace std;
int weight;
double height;
double BMI;
int main() {
cout<<"Enter your weight: "<<endl; cin>>weight;
cout<<"Enter your height: "<<endl; cin>>height;
BMI=weight/pow(height,2);
cout<<"BMI value: "<<BMI<<endl;
if(BMI<15){
cout<<"Very severely underweight"<<endl;}
if(BMI>15 && BMI<16){
cout<<"Severely underweight"<<endl;
}
if(BMI>16 && BMI<18.5){
cout<<"Underweight"<<endl;
}
if(BMI>18.5 && BMI<25){
cout<<"Normal (healthy weight)"<<endl;
}
if(BMI>25 && BMI<30){
cout<<"Overweight"<<endl;
}
if(BMI>30 && BMI<35){
cout<<"Obese Class I (Moderately obese)"<<endl;
}
if(BMI>35 && BMI<40){
cout<<"Obese Class II (Severely obese)"<<endl;
}
if(BMI>40){
cout<<"Obese Class III (Very severely obese)"<<endl;
}
return 0;
}
11. BMI Calculator by Ray Joe
Made by Ray Joe. Source
Enter your weight in kilograms: 60 Enter your height in metres: 170 Results: 20.76 You are Normal.
#include <iostream>
#include <iomanip>
class BMI
{
double weight;
double height;
public:
BMI();
~BMI();
double EvaluateBMI(double&,double&);
};
void ExecuteCalculator();
void LoopState()
{
std::cout << " Do you want to reset the BMI calculator[Y/N]? ";
char option;
std::cin >> option;
switch(option)
{
case 'Y':
case 'y':
ExecuteCalculator();
break;
case 'N':
case 'n':
break;
default:
do
{
std::cout << '\n';
std::cout << " Invalid entry!\n\n";
std::cin.clear();
std::cin.ignore(100, '\n');
LoopState();
} while (!(std::cin >> option));
}
}
int main(int argc, char* argv[])
{
ExecuteCalculator();
return 0;
}
BMI::BMI():weight(0), height(0){}
BMI::~BMI(){}
double BMI::EvaluateBMI(double& weight,double& height){
double firstResult;
double finalResult;
firstResult = weight / height;
finalResult = firstResult / height;
return finalResult;
}
void ExecuteCalculator()
{
BMI bmi;
double weight;
double height;
std::cout << '\n';
std::cout << " ---------------\n";
std::cout << " BMI Calculator\n";
std::cout << " ---------------\n";
std::cout << '\n';
std::cout << " Enter your weight in kilograms: ";
std::cin >> weight;
std::cout << " Enter your height in metres: ";
std::cin >> height;
std::cout << '\n';
double results = bmi.EvaluateBMI(weight,height);
std::cout << " Results: ";
std::cout << std::setprecision(4) << results;
std::cout << '\n';
if(results >= 35)
{
std::cout << " You are very obese.";
}
else if(results >= 30 && results <= 34.9)
{
std::cout << " You are obese.";
}
else if(results >= 25 && results <= 29.9)
{
std::cout << " You are overweight.";
}
else if(results >= 18.5 && results <= 24.9)
{
std::cout << " You are Normal.";
}
else if(results >= 16 && results <= 18.4)
{
std::cout << " You are underweight.";
}
else
{
std::cout << " You are very underweight.";
}
std::cout << "\n\n";
LoopState();
std::cout << '\n';
}