Your Task Produce a Biggest Loser progress tracker which will compute team membe
ID: 3710330 • Letter: Y
Question
Your Task
Produce a Biggest Loser progress tracker which will compute team members’ body mass indexes and then tally the number of overweight, underweight, and healthy weight participants. Follow these specs closely; your exam grade depends on your ability to follow written instructions and convert them to working code.
Write a function called calc_bmi. This function will return a char type. This function will also have two float parameters called ht and wt to represent a participant’s height and weight at weigh-in.
Inside your calc_bmi function you will:
Create a float variable called bmi and a char variable called status;
Compute the body mass index and assign that number to the bmi variable. The formula for body mass index is: BMI = 703*weight/ height^2
Code an if/else to assign a letter to the status variable depending on the participant’s BMI. Use the following values:
BMI Range
Letter to assign your status variable
Over 25
‘o’ (as in overweight)
Under 16.5
‘u’ (as in underweight)
16.5 - 25
‘’ (null escape sequence –or backslash zero)
Return the value of status back to main
2, In main, create variables as follows:
int numParticipants = 0;
float height, weight;
char bmi_classification;
int numOverweight = 0, numUnderweight = 0, numOptimal = 0;
3, Get the number of challenge participants from the user. Use a “while” loop to ensure the user can only enter a number of participants between 1 and 10 (see sample output below).
4, Once the user enters an appropriate number of participants, write a separate “for” loop to run that many times. Inside the for loop, you will:
Prompt the user for the participant’s height and weight (see sample output) and use cin to read those values into the height and weight variables.
Call the calc_bmi function, passing the height and weight values as arguments. Capture the return value from the function into the bmi_classification variable.
Use an if/else to assess the value in the bmi_classification variable and increment the appropriate tally variable. For example, if bmi_classification has a value of ‘o’, you will code numOverweight++; if ‘u’, you will code numUnderweight++; and so on…
5, The very last thing you will do in main (note: the loop is over now and we are not inside any loop) is display the team progress report. Use the sample output below as your model. Further output requirements are on the next page.
SAMPLE OUTPUT
How many Biggest Losers are participating in this challenge? (1-10): 11
How many Biggest Losers are participating in this challenge? (1-10): 20
How many Biggest Losers are participating in this challenge? (1-10): 3
Enter participant 1's height in inches: 60
Enter participant 1's weight in pounds: 100
Enter participant 2's height in inches: 65
Enter participant 2's weight in pounds: 175
Enter participant 3's height in inches: 73
Enter participant 3's weight in pounds: 250
**************************************
* BIGGEST LOSER TEAM PROGRESS REPORT *
**************************************
Percentage overweight 66.7%
Percentage underweight 0.0%
Percentage optimal weight 33.3%
Press any key to continue . . .
The percentage of overweight, underweight, and optimal weight can be obtained by dividing those respective tallies by the number of participants. Be mindful of integer division and use the static_cast operator as necessary. Also multiply the result by 100 so it displays as a percentage and not a decimal. Display the percentage with one decimal place and a trailing percent sign.
Use setw to set the print field widths as follows:
The classification labels (e.g., “Percentage overweight”) are printed in a field 25 characters wide.
The percentages (e.g., “66.7%”) are printed in a field 10 characters wide.
When you are done, submit your .cpp file through Canvas. The link to submit can be found at the top of the Modules page.
BMI Range
Letter to assign your status variable
Over 25
‘o’ (as in overweight)
Under 16.5
‘u’ (as in underweight)
16.5 - 25
‘’ (null escape sequence –or backslash zero)
Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
char calc_bmi(float height,float weight)
{
char letter;
float bmi = (703*weight)/ (height*height);
if(bmi > 25) letter = 'o';
else if(bmi < 16.5) letter = 'u';
else if(bmi >= 16.5 && bmi <= 25) letter = '';
return letter;
}
int main() {
int numParticipants = 0;
float height, weight;
char bmi_classification;
int numOverweight = 0, numUnderweight = 0, numOptimal = 0;
do
{
cout<<" How many Biggest Losers are participating in this challenge? (1-10): ";
cin>>numParticipants;
}while(numParticipants > 10);
cout<<endl;
cout<<fixed<<setprecision(1)<<setw(25); // one decimal point in output
for(int i=1;i<=numParticipants;i++)
{
cout<<" Enter participant "<<i<<" 's height in inches: ";
cin>>height;
cout<<" Enter participant "<<i<<" 's weight in pounds: ";
cin>>weight;
bmi_classification = calc_bmi(height,weight);
switch(bmi_classification)
{
case 'o' : numOverweight++;
break;
case 'u' : numUnderweight++;
break;
case '' : numOptimal++;
break;
default: break;
}
cout<<endl;
}
cout<<" **************************************";
cout<<" * BIGGEST LOSER TEAM PROGRESS REPORT *";
cout<<" **************************************";
cout<<" Percentage overweight "<<static_cast<float>(numOverweight)/(numOverweight+numUnderweight+numOptimal)*100<<"%";
cout<<" Percentage underweight "<<static_cast<float>(numUnderweight)/(numOverweight+numUnderweight+numOptimal)*100<<"%";
cout<<" Percentage optimal weight "<<static_cast<float>(numOptimal)/(numOverweight+numUnderweight+numOptimal)*100<<"%";
cout<<" Press any key to continue . . .";
return 0;
}
Output:
How many Biggest Losers are participating in this challenge? (1-10):11
How many Biggest Losers are participating in this challenge? (1-10):20
How many Biggest Losers are participating in this challenge? (1-10):3
Enter participant 1 's height in inches:60
Enter participant 1 's weight in pounds:100
Enter participant 2 's height in inches:65
Enter participant 2 's weight in pounds:175
Enter participant 3 's height in inches:73
Enter participant 3 's weight in pounds:250
**************************************
* BIGGEST LOSER TEAM PROGRESS REPORT *
**************************************
Percentage overweight 66.7%
Percentage underweight 0.0%
Percentage optimal weight 33.3%
Press any key to continue . . .
Do ask if any doubt. Please upvote
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.