2. W rite a program that asks for the user\'s height, weight, and age, and then
ID: 3888732 • Letter: 2
Question
2. W rite a program that asks for the user's height, weight, and age, and then computes clothing sizes according to the formulas: Hat size = weight in pounds divided by height in inches and all that multiplied by 2.9 Jacket size (chest in inches)-height times weight divided by 288 and then adjusted by adding 1/8 of an inch for each 10 years over age 30. (Note that the adjustment only takes place after a full 10 years. So, there is no adjustment for ages 30 through 39, but 1/8 of an inch is added for age 40.) Waist in inches = weight divided by 5.7 and then adjusted by adding 1/10 of an inch for each 2 years over age 28. (Note that the adjustment only takes place after a full 2 years. So, there is no adjustment for age 29, but 1/10 of an inch is added for age 30.) Use functions for each calculation. Your program should allow the user to repeat this calculation as often as the user wishes.Explanation / Answer
Answer- C++ Program to calculate the hat, waist, and jacket size of the user when given age, height, and weight (wth all functions as required in question).
#include <iostream>
using namespace std;
double hat(double weight,double height); // Function Prototypes
double jacket(double height,double weight,int age);
double waist(double weight,int age);
int main ()
{
double height,weight;
int age;
char answer;
cout.setf(ios::fixed); //codes are used to round the output to the 2 decimal places
cout.setf(ios::showpoint);
cout.precision(2);
do
{
cout<< "Enter the user's height in inches: ";
cin>>height;
cout<< "Enter the user's' weight in pounds: ";
cin>>weight;
cout<< "Enter the user's' age: ";
cin>>age;
cout<< " The user's Hat size: " << hat(weight,height) << " The user's Jacket size: "<< jacket( height, weight, age) << " The user's Waist size: "<< waist(weight,age)<< " Would you like to continue (y/n)? ";
cin>>answer;
}
while(toupper(answer) == 'Y');
return 0;
}
double hat(double weight,double height)
{
return weight/height * 2.9;
}
double jacket(double height,double weight,int age)
{
double size;
int j;
if (age>=30)
{
if((age % 10) !=0)
age = age-(age%10);
j= (age-30)/10;
size =((height * weight) / 288)+((1.0/8)*j);
}
else
size =((height * weight) / 288);
return size;
}
double waist(double weight,int age)
{
double size2;
int k;
if(age >= 28)
{
if((age % 2) !=0)
age = age-(age%2);
k = (age-28)/2;
size2 = (weight/(5.7))+( (1.0/10)*k);
}
else
size2 = weight / (5.7);
return size2;
}
OUTPUT-
Enter the user's height in inches: 65
Enter the user's' weight in pounds: 155
Enter the user's' age: 33
The user's Hat size: 6.92 The user's Jacket size: 34.98 The user's Waist size: 27.39
Would you like to continue (y/n)? Y
Enter the user's height in inches: 65
Enter the user's' weight in pounds: 155
Enter the user's' age: 40
The user's Hat size: 6.92 The user's Jacket size: 35.11 The user's Waist size: 27.79
Would you like to continue (y/n)? Y
Enter the user's height in inches: 65
Enter the user's' weight in pounds: 155
Enter the user's' age: 28
The user's Hat size: 6.92 The user's Jacket size: 34.98 The user's Waist size: 27.19
Would you like to continue (y/n)? Y
Enter the user's height in inches: 65
Enter the user's' weight in pounds: 155
Enter the user's' age: 30
The user's Hat size: 6.92 The user's Jacket size: 34.98 The user's Waist size: 27.29
Would you like to continue (y/n)? N
...Program finished with exit code 0
Press ENTER to exit console.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.