i need to write a program that calculates hat size, jacket size and waist size after asking a user their height, weight and age. my problem is coming to the jacket size. the first part is easy, its to multiply height and weight, and divide that by 288, then, if your above 40 years old, add 1/8 of an inch to your total waist size(like age 40 you add 1/8, age 50 u add 1/4 ect). i was able to do it, but i did it for every ten years, so it felt like cheating. how would i be able to write it so that it adds the 1/8 inch for every year?
here is my code so far, this is working just fine.
**btw im new to programming, i might be using long double wrong**
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double height,weight,age;
cout<< " Enter your height in inches ";
cin>>height;
cout<< "enter you weight in pounds ";
cin>> weight;
cout<<"enter you age ";
cin>>age;
long double hatsize;
hatsize=(weight/height)*2.9;
cout<< hatsize<<endl;
long double jacketsize;
jacketsize=(height*weight)/288;
if (age==40)
jacketsize=jacketsize+0.125;
else if (age==50)
jacketsize=jacketsize+0.25;
else if (age==60)
jacketsize=jacketsize+0.375;
else if (age==70)
jacketsize=jacketsize+0.5;
else if (age==80)
jacketsize=jacketsize+0.75;
else if (age==90)
jacketsize=jacketsize+0.875;
else if (age==100)
jacketsize=jacketsize+1;
cout<<jacketsize<<endl;
return 0;
}
First, you're comparing ==, not >=. Now if age is 41, nothing is added.
As for the actual problem. Notice that increment is a linear function of Age. Age/10 rounded down, specifically.
Increment = (Age/10-3)*0.125
This can also be done with a for loop. I'll leave that for you to think about (although the formula is a superior approach).