Question is... Write a program that asks for th user`s height, weight, and age,
ID: 3630224 • Letter: Q
Question
Question is...
Write a program that asks for th user`s height, weight, and age, and then computes clothing szies according to the formulas:
*Hat size = weight in pounds divided by height in inches and all that multiplies 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 throught 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.)
#include <iostream>
using namespace std;
double Hat_size(double weight_H, double height_H);
//The formal parameter named weight_H is the weight of the user
//The formal parameter named height_H is the height of the user
double jacket_size (double weight_J, double height_J, int age_J);
//The formal parameter named weight_J is the weight of the user
//The formal parameter named height_J is the height of the user
//The formal parameter named age_J is the user`s age
double waist_inches (double weight_W);
//The formal parameter named weight_W is the wieght of the user
int main()
{
double weight, height;
int age;
double size_of_hat;
double size_of_jacket;
char ans;
do
{
cout << "Enter your height, weigh, and age :"<<endl;
cin >> weight >> height >> age;
size_of_hat=Hat_size(weight,height);
cout << "Your hat size is " <<size_of_hat<<endl;
size_of_jacket=jacket_size(weight,height,age);
cout << "Your Jacket size is "<<size_of_jacket<<endl;
}while (ans=='y'||ans=='Y');
return 0;
}
double Hat_size(double weight_H, double height_H)
{
return((weight_H/height_H)*2.9);
}
double jacket_size(double weight_J, double height_J, int age_J)
{
const double size = (weight_J*height_J)/288;
size=jacket_size;
while(age_J>30)
{
if(age_J%10==0)
jacket_size+=0.125;
jacket_size++;
}
return (jacket_size);
}
======
Last double jacke_size part has problem, but I don`t understand.
Can you save worst programmer?
Explanation / Answer
const double size = (weight_J*height_J)/288;
this line, if you declare a constant, its name should be capitalized, but it's not the real problem here, just coding standards.
size=jacket_size;
and this line means you are assigning the double jacket_size to the constant double SIZE, which cannot be done because SIZE is a constant. Beside, jacket_size is the name of the function and should not appear in the body { } of the function, except if you want to do recursion. Try declare another double jacketSize such as:
double jacketSize = SIZE;
Full solution here:
//INCLUDES
#include
#include
using namespace std;
//MAIN
int main()
{
//PROTOTYPES
double hatSize(double height, double weight);
double jacketSize(double height, double weight, int age);
double waist(double weight, int age);
//LOCAL DECLARATIONS
double weight, height;
int age;
char ans;
//PROCEDURES
do
{
cout << "Enter your height (inches): ";
cin >> height;
cout << "Enter your weight (pounds): ";
cin >> weight;
cout << "Enter your age: ";
cin >> age;
cout << fixed << setprecision(2);
cout << endl;
cout << "Your hat size is " << hatSize(height, weight) << endl;
cout << "Your jacket size is " << jacketSize(height, weight, age) << " inches" << endl;
cout << "Your waist is " << waist(weight, age) << " inches" << endl;
cout << endl;
cout << "Try again? ";
cin >> ans;
} while (ans == 'y' || ans == 'Y');
return 0;
}
//---------------------------------------------------------
// FUNCTION DECLARATIONS
//---------------------------------------------------------
double hatSize(double height, double weight)
{
return weight / height * 2.9;
}
//---------------------------------------------------------
double jacketSize(double height, double weight, int age)
{
double ageAdjustment = ( (age - 30) / 10 ) * 1.0 / 8.0;
return height * weight / 288.0 + ageAdjustment;
}
//---------------------------------------------------------
double waist(double weight, int age)
{
double ageAdjustment = ( (age - 28) / 2 ) * 1.0 / 10.0;
return weight / 5.7 + ageAdjustment;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.