The body mass index (BMI) is a measure of relative weight based on height and we
ID: 3854196 • Letter: T
Question
The body mass index (BMI) is a measure of relative weight based on height and weight. Write a program in C# that calculates and prints the BMI for aperson; the program allows user to enter values for the name, weight and height of the person. The formula for BMI is: BMI = (Weight in Pounds / (Height in inches) 2 ) * 703
1. Write the following input, calculation and display methods.
a. Input method prompts user to enter name of the person and returns name (a string). (10 points)
b. Input methods (2) prompts user to enter weight in pounds, height in inches of the person and returns weight (a double) and height (a double).(20 points)
c. Calculation method: parameters of calculation method are weight and height (doubles); the method calculates and returns the BMI corresponding to its parameters. (20 points)
d. Display method: print out name, weight, height and BMI of the person. (20 points)
2. Call your methods in Main() to get the input, perform the calculation and display the results. (20 points)
3. Test your program with different inputs. (10 points)
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
int weight;
float height,BMI;
cout<<"Please enter your weight in pounds: ";
cin>>weight;
cout<<" Please enter your height in inches: ";
cin>>height;
BMI =weight*703/(height*height);
cout<<" Your body mass Index is: "<<BMI;
if (BMI>25)
cout<<" You are somewhat overweight.";
else if (BMI<18.5)
cout<<" You are somewhat underweight.";
else if (BMI>18.5 && BMI <25)
cout<<" Congratulations! You are within a healthy weight range.";
cin.get ();
cin.get ();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.