Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

BMI Calculator Program in C++

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

void main()
{
	double Weight, height, BMI;
	//Ask user to enter weight.
	cout << "=========================================

";
	cout << setw(30) << "Enter Weight in pound: ";
	cin >> Weight;
	//Ask user to enter height.
	cout << "
=========================================

";
	cout << setw(30) << "Enter height in inches: ";
	cin >> height;
	cout << "
=========================================

";
	//const kg = 0.45359237.
	const double Kg_per_pound = 0.45359237;
	//const height = 0.025.
	const double Mtr_per_inch = 0.025;
	//weight * Kg_per_pound.
	double WeightInKg = Weight * Kg_per_pound;
	//height * Mtr_per_inch.
	double heightInInches = height * Mtr_per_inch;
	//BMI = Kg / m2.
	BMI = WeightInKg / (heightInInches * heightInInches);
	//Display BMI.
	cout << setw(18) << "BMI: " << BMI << endl;
	cout << "
=========================================

";
	//if()......else().
	if (BMI < 18.5)
		cout << setw(22) << "Underweight." << endl;
	else if (18.5 <= BMI < 25.0)
		cout << setw(22) << "Normal." << endl;
	else if (25.0 <= BMI < 30.0)
		cout << setw(22)<< "Overweight." << endl;
	else if (30.0 <= BMI)
		cout << setw(22)<< "Obese." << endl;
	cout << "
=========================================
";
}
Source by codejudge.blogspot.com #
 
PREVIOUS NEXT
Tagged: #BMI #Calculator #Program
ADD COMMENT
Topic
Name
2+9 =