Help with basic functions

I'm having trouble figuring out how to write the math for part of the function below. How would I account for the 1/8 inch adjustment for every 10 years over age 30?


Problem: Write a program that asks for the user’s height, weight, and age, and then computes clothing sizes according to the formulas:

• 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.)


***This was my attempt so far at writing a function for jacket size.

1
2
3
4
5
double jacket (double h, double w) {
	double jacketsize;
	jacketsize = (h*w)/288;
	return jacketsize;
}
Last edited on
closed account (o3hC5Di1)
Hi there,

That's a pretty decent start. You will also need to accept the age in your function argument list. Then you can do something like the following:

1
2
3
4
5
6
7
8
constexpr double inch_multiplier = 1.0/8;  //1/8th of an inch will be the multiplier

if (age >= 40)
{
    age -= 30; //don't account for first 30 years
    int full_decades = age/10; //calculate amount of decades
    jacketsize += full_decades*inch_multiplier; //multiply decades by 1/8th of an inch
}


Hope that helps, please do let us know if you require any further help.

All the best,
NwN
Last edited on
1
2
3
4
5
6
7
8
double jacket (double h, double w, double a) 
{
	double jacketsize;
	int decades_over_thirty = (a - 30) / 10;
	jacketsize = (h*w)/288;
	jacketsize = jacketsize + (decades_over_thirty * 0.125);
	return jacketsize;
}
Actually...

1
2
3
4
5
6
7
8
9
10
11
double jacket (double h, double w, double a) 
{
	double jacketsize;
	jacketsize = (h*w)/288;
	if(a >= 40) 
	{
		int decades_over_thirty = (a - 30) / 10;
		jacketsize = jacketsize + (decades_over_thirty * 0.125);
	}
	return jacketsize;
}
Topic archived. No new replies allowed.