Every 11 years, add certain amount

Sep 26, 2021 at 4:29pm
I'm stuck on this part of my homework. Everything else works, except for one function. I need to add 1/7 of an inch for every 11 years over the age of 31. I honest to God have no idea how to do that or where to even start.
Sep 26, 2021 at 4:33pm
age - 31 gives you the number of years over 31

That divided by 11 gives you the 'n' to multiply by 1/7th.

Seems basic maths, rather than programming.
Sep 26, 2021 at 5:06pm
But how would I make it so that it's every 11 years versus a random number? I need to add 1/7 of an inch every 11 years, which means at age 42, the user would go up 1/7 of an inch and then again at 53 and again at 64. I'm not sure if I'm reading the question wrong either so here's the original post.

"One function will calculate your vest size by multiplying your height by your weight and dividing that by 300. Also add 1/7 of an inch for each 11 years over the age of 31."
Sep 26, 2021 at 5:25pm
1
2
3
4
5
6
7
8
double vestsize(double height, double weight, int age ) {
  double size = height * weight * 300;
  if ( age > 31 ) {
    int elder = age - 31;
    int numberOfElevens = elder / 11;  // integer truncation
    size += numberOfElevens * (1.0 / 7.0);
  }
}
Sep 26, 2021 at 5:55pm
fucking life saver. Thanks a lot.
Topic archived. No new replies allowed.