Search
 
SCRIPT & CODE EXAMPLE
 

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 << "
=========================================
";
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ absolute value 
Cpp :: prime number program in c c++ 
Cpp :: c++ std::fmin 
Cpp :: c++ std::copy to cout 
Cpp :: c++ get last character of string 
Cpp :: qt double en qstring 
Cpp :: freopen c++ 
Cpp :: c++ loop pyramid 
Cpp :: point is on line 
Cpp :: convert string to char c++ 
Cpp :: minimum and maximum value of a vector in C++ 
Cpp :: insertion sort c++ 
Cpp :: create a dictionary cpp 
Cpp :: cpp split string by space 
Cpp :: sort function descending c++ 
Cpp :: combination code c++ 
Cpp :: switch case with string c++ 
Cpp :: conditional operator in cpp 
Cpp :: string to number in c++ 
Cpp :: appending int to string in cpp 
Cpp :: how to get length of a file in c++ 
Cpp :: c++ random number 0 to 1 
Cpp :: how to check if a number is prime c++ 
Cpp :: c++ template example 
Cpp :: how to make a typing effect c++ 
Cpp :: c++ programming language 
Cpp :: count bits c++ 
Cpp :: sort 0 1 2 leetcode 
Cpp :: c++ call by reference 
Cpp :: convert unsigned long to string c++ 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =