Horje
BMI Calculator Program in C++ Code Example
BMI Calculator Program in C++
#include<iostream>
#include<iomanip>
using namespace std;

void main()
{
	double Weight, height, BMI;
	//Ask user to enter weight.
	cout << "=========================================\n\n";
	cout << setw(30) << "Enter Weight in pound: ";
	cin >> Weight;
	//Ask user to enter height.
	cout << "\n=========================================\n\n";
	cout << setw(30) << "Enter height in inches: ";
	cin >> height;
	cout << "\n=========================================\n\n";
	//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 << "\n=========================================\n\n";
	//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 << "\n=========================================\n";
}




Cpp

Related
runtime Code Example runtime Code Example
Character convert c++ Code Example Character convert c++ Code Example
How to execute a command and get return code stdout and stderr of command in C++ Code Example How to execute a command and get return code stdout and stderr of command in C++ Code Example
pain Code Example pain Code Example
stack implementation Code Example stack implementation Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9