1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
/*
The federal government developed a body mass index (BMI) to determine ideal weights.
Body mass index is calculated as 703 times the weight in pounds divided by the square of the height in inches. Then round this value to the nearest whole number
Write a program to input a person’s weight in pounds and height in inches.
Compute and output the person’s body mass index. Note: A BMI of 19 to 25 corresponds to a healthy weight.
Use three functions in addition to main(): one for input, one for all calculations, and one for the output.
Your name as a comment and printed out with cout object
Output for weigh 125 and height 54 inches should be copied and pasted below code as a comment
Pre and Post statements are absolutely necessary (but no other comments besides your name are necessary on this little "Hands On"
*/
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <ctype.h>
#include <stdlib.h>
using namespace std;
// Function Prototypes
void input(double weight, double height);
double calcBMI(double weight, double height);
void output(double weight, double height, double BMI);
int main()
{
double weight = 0.0, height = 0.0;
double BMI = 0.0;
input(weight, height);
BMI = calcBMI(weight, height);
output(weight, height, BMI);
system("pause");
return 0;
}
void input(double weight, double height)
{
cout << "Enter Weight: ";
cin >> weight;
cout << "Enter Height: ";
cin >> height;
return;
}
double calcBMI(double weight, double height)
{
double answer = 0.0;
answer = (703 * weight) / (height * height);
return answer;
}
void output(double weight, double height, double BMI)
{
cout << setprecision(2) << fixed;
cout << "Weight: " << weight << endl;
cout << "Height: " << height << endl;
cout << "BMI: " << BMI << endl;
return;
}
|