Question

Write a function which asks users to enter names, heights, and weights of eachperson. For simplicity,...

Write a function which asks users to enter names, heights, and weights of eachperson. For simplicity, let's assume names contain no white space - for example, justfirst names like John, Mike or Luke (so you can use cin >> name to get the name).Also assume height will range from 1.3 to 2.0 meters (which means if someoneenters a height that is less than 1.3 or greater than 2.0, show an error message andkeep asking user to enter them until they enter the correct value) and assume weightranges from 40 to 150 kg (so if user enters weight that less than 40 or greater than150 then show error message and keep asking user to enter again until they enterthe correct value) .Hint: create one array to store names, one array to store heightsand one array to store weights.3.Write a function to calculate the BMI from each weight and height collected above.The formula for BMI isBMI = weight / (height * height)Hint: Create an array BMIs that has the same size as the 3 arrays above: eachelement in the BMIs array will correspond to the BMI of each person.4.Write a function to display results: The text of result is up to you but it must have: theperson name, the BMI of that person and the result from that BMI (underweight,normal weight over weight or obese). Hint: read the first part of the question to findout how to determine underweight, normal weight, ... based on BMI.5.Inside the main function, use those functions you created above to ask the user enterinformation, calculate BMI and display the result

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code:

#include <iostream>
using namespace std;
void getData();
void calculateBMI(); //functio prototypes
void display();
string names[5];
double height[5]; //declarig global varables
double input;
double weight[5];
double BMI[5];
int main()
{
getData(); //reading input data
calculateBMI(); //calculating bmi
display(); //prinitng details
return 0;
}
void getData()
{
for(int i=0;i<5;i++)
cin>>names[i];
for(int i=0;i<5;i++)
{
cin>>input;
while(input<1.3 ||input>2.0)
{
cout<<"enter corrct coorect values"<<endl;
cin>>input;
}
height[i]=input;
}
for(int i=0;i<5;i++)
{
cin>>input;
while(input<40 ||input>150)
{
cout<<"enter corrct weight values coorect values"<<endl;
cin>>input;
}
weight[i]=input;;
}
for(int i=0;i<5;i++)
{
cout<<names[i]<<" ";
cout<<height[i]<<" ";
cout<<weight[i]<<" ";
cout<<endl;
}

}
void calculateBMI()
{
for(int i=0;i<5;i++)
{
double b;
b=weight[i]/(height[i]*height[i]);
BMI[i]=b;
}
}
void display()
{
for(int i=0;i<5;i++)
{
cout<<names[i]<<":";
cout<<BMI[i];
if(BMI[i]<=18.5)
cout<<"under Weight"<<endl;
else if(BMI[i]>18.5&&BMI[i]<=24.9)
cout<<"normal weight"<<endl;
else if(BMI[i]>25&&BMI[i]<=29.9)
cout<<"over weight"<<endl;
else if(BMI[i]>=30)
cout<<"obesity"<<endl;
}
}

OUTOUT:

ram
laxman
venkat
suresh
kiran
1.4
1.0
enter corrct coorect values
2.2
enter corrct coorect values
1.6
1.8
1.9
40
enter corrct coorect values
1.7
45
185
enter corrct weight values coorect values
23
enter corrct weight values coorect values
65
86
66
90
ram 1.4 45
laxman 1.6 65
venkat 1.8 86
suresh 1.9 66
kiran 1.7 90
ram:22.9592normal weight
laxman:25.3906over weight
venkat:26.5432over weight
suresh:18.2825under Weight
kiran:31.1419obesity

screenshot:



Add a comment
Know the answer?
Add Answer to:
Write a function which asks users to enter names, heights, and weights of eachperson. For simplicity,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C Write a function that asks for the user's first, middle, and last names. The...

    In C Write a function that asks for the user's first, middle, and last names. The names will be entered by the user on a single line and will be stored in three different C-strings. The program should then store, in a fourth array, the name arranged in the following manner: the last name followed by a comma and a space, followed by the first name and a space, followed by the middle name. For example, if the user entered...

  • Using python, write a program that lets the user enter this information: First name & Last...

    Using python, write a program that lets the user enter this information: First name & Last name weight age gender height systolic & diastolic blood pressure body temperature in Fahrenheit After the information has been entered, the results should be printed on the display based on the information below -BMI -Temp Conversion -Mean blood pressure -weight conversion (lbs to kg) -height conversion (inches to cm) The output should look like: First Name Last name is ___ cm and ____kgs. First...

  • Y F G Prompt and Store. 5. Prompt the user with "Enter your weight in pounds:...

    Y F G Prompt and Store. 5. Prompt the user with "Enter your weight in pounds: "message and store in the weight variable. 6. Initialize an int variable named heightIn Inches to feet OſHeight times 12 plus Inches OfHeight. 7. Initialize a double variable named BMI to weight * 703.0 heightIrinches El VB 8. Initialize a double variable named ratio to height In Inches? 703.0 9. Initialize a double variable named lower Normal to 18.5 times ratio. 10. Initialize a...

  • Write a Java program that performs these operations Prompt the user to enter a low height...

    Write a Java program that performs these operations Prompt the user to enter a low height in feet (an integer) Prompt the user to enter a high height in feet (an integer) Prompt the user to enter a low weight in pounds (an integer) Prompt the user to enter a high weight in pounds (an integer) Print a table of Body Mass Index (BMI) for the heights and weights entered, ranging from the low height to the high height (inclusive),...

  • You are working as a software developer for a large insurance company. Your company is planning...

    You are working as a software developer for a large insurance company. Your company is planning to migrate the existing systems from Visual Basic to Java and this will require new calculations. You will be creating a program that calculates the insurance payment category based on the BMI score. Your Java program should perform the following things: Take the input from the user about the patient name, weight, birthdate, and height. Calculate Body Mass Index. Display person name and BMI...

  • Using C++ cs 102 REVIEW LAB Selection a) Minimum/Maximum: Nrite a program that asks the user...

    Using C++ cs 102 REVIEW LAB Selection a) Minimum/Maximum: Nrite a program that asks the user to enter two numbers. The progzan should use the conditional operator to determine which number is the smaller and which is the larger. Display your output in the format below: The smaller number is: (smallerNumber) The larger number is: ClargerNumber] b) Areas of Rectangles: The area of a rectangle is calculated by maltiplying its length tines its width. Write a program that asks the...

  • c++ pls 10D yUur Tugt Sna you will have to re-take it at another time PROBLEM...

    c++ pls 10D yUur Tugt Sna you will have to re-take it at another time PROBLEM 1 Body Mass Index (BMI) is a measure of body fat that is useful in screening for health issues. To calculate a BMi, you need the height in inches and the weight in pounds. You square the height, then divide the weight in pounds by the squared-height. BMI is defined in terms of meters and kilograms, so to convert from pounds and inches to...

  • Write a C++ program that asks user number of students in a class and their names....

    Write a C++ program that asks user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’ names and ranking. Follow the Steps Below Save the project as A4_StudentRanking_yourname....

  • read instructions carefully please matlab only Write a MATLAB function for a BMI calculator that receives the inputs for body weight (lbs)and height (ft) from the user's program, calculates th...

    read instructions carefully please matlab only Write a MATLAB function for a BMI calculator that receives the inputs for body weight (lbs)and height (ft) from the user's program, calculates the BMI using the equation below, displays the BMI category, and outputs the BMI value tothe user's program W (kg) h2 (m2) BMI Display Normal if 18.5 s BMI 25 Display Overweight if 25 s BMI <30 Display Obese if BMI 2 30 Else display underweight So you will create two...

  • NOTE: Use JOptionPane NOT Scanner Please Write an application that allows a user to enter the...

    NOTE: Use JOptionPane NOT Scanner Please Write an application that allows a user to enter the names and birthdates of up to 10 friends. Continue to prompt the user for names and birthdates until the user enters the sentinel value ZZZ for a name or has entered 10 names, whichever comes first. When the user is finished entering names, produce a count of how many names were entered, and then display the names. In a loop, continuously ask the user...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT