adjusting based off age.

Hey I hope this is the right place, I'm taking C++ for my first programming class in college and I have a problem that I need to solve. I am writing a function for finding jacket size and I need to add 1/8 inch for every 10 years starting at age 30. Every 10 years you need to add another 1/8 inch so from 30-39 its 1/8 from 40-49 its 1/4 and so on. How would I write this in the function? Thanks!
Well, take their age, subtract 30, then subtract modulo 10, then divide by 10, then multiply by 1/8 inch and add that number to the jacket size.
I'm sorry, but modulo 10? Ha I am sorry if I am being slow, but what does that mean? I think I get what you're saying but not that final piece.
We're missing some information, You didn't define what size they were at age 30. I'm assuming we don't want to extrapolate from age 0/size0.

1
2
3
4
5
double get_size(int age)
{
    const double size_at_30 = 60; // Change this;
    return ((age-30.)/80.) + size_at_30;
}
subtract modulo 10
means to subtract from whatever value you have the remainder of division by 10, or in other words, round down to the closest 10:

1
2
3
4
int x = 17; // x = 17
cout << x % 10; // Output: 7
cout << x - (x % 10); // Output: 10
cout << (x - (x % 10)) / 10 // Output: 1 
Their size is a variable being inputed by the user. What I have right now is:
{

int height, age, weight;
double hat_size, jacket_size, waist_in_inches;

cout<<"Enter your height: "<<endl;
cin>>height;
cout<<"Enter your age: "<<endl;
cin>>age;
cout<<"Enter your weight: "<<endl;
cin>>weight;
hat_size=hat_function(weight, height);
cout<<"Your hat size is: "<<hat_size<<endl;

return 0;
}

double hat_function(double weight_in_lbs, double height_inches)
{
double hat_multiple=2.9, hat_size;
hat_size=(weight_in_lbs/height_inches)*hat_multiple;
return hat_size;
}

double jacket_function(double weight, double height)
{

}
sorry I didn't put my code in the nice box xD
Starting size is irrelevant. Even if it's 0, then you'll start off with 1/8 inch, because you're adding to the value.
I GET IT! so i put that in a if-else statement saying: if (age >= 30)
{
((age-(age%10))/10)*(1/8)
}

so if they were 34 it would be
34-4=30
30/10=3
3*1/8= 3/8
there is my addition.
YOU GUYS ROCK!!
ciphermagi thank you so much!
You forgot the part where you subtract 30. in order to start at 30, instead of starting at 0...
Topic archived. No new replies allowed.