Not getting results i want...

I have a assignment for class and it goes like this...

Write a program that asks for the user’s height, weight, and age, and then computes clothing sizes according the following formula:
Hat size= weight in pounds divided by heights in inches and all that multiplied by 2.9.

Jacket size in inches)=height times weight divided by 288 and then adjusted by adding one-eighth 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 one-eight of an inch is added for age 40.)

Waist in inches=eight divided by 5.7 and then adjusted by adding one –tenth 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 one-tenth of an inch is added for age 30.)

This is what I came up with.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  #include <stdio.h>
#include <ctime>
#include <iostream>
#include <math.h>
using namespace std;

void clothingSize(int height, int weight, int age);

int main(){
int height, weight, age;
cout << "Enter your height in inches: ";
cin >> height;
cout << endl;
cout << "Enter your weight in pounds: ";
cin >> weight;
cout << endl;
cout << "Enter your age: ";
cin >> age;
cout << endl;

clothingSize(height, weight, age);
}

void clothingSize(int height, int weight, int age){

double hatSize = (weight/height)*2.9;
double jacketAdjustment = 0;
double waistAdjustment = 0;
int age1 = age;
int age2 = age;
if(age > 39){
    for(int i = 0; i < age1-39; i+=10){
        jacketAdjustment+=1/8;
    }
}
double jacketSize = ((height*weight)/288)+jacketAdjustment;

if (age > 29){
    for(int j = 0; j < age2-28; j+=2){
        waistAdjustment+=1/10;
    }
}

double waistSize = (8/5.7)+waistAdjustment;

cout << "Your hat size is: " << hatSize <<
" Your jacket size is: " << jacketSize <<
", Your waist size is: " <<  waistSize;
}




The two for loops don't seem to work and I was wondering what the problem was. Thanks in advance.
Last edited on
> jacketAdjustment+=1/8;
integer division returns an integer, so 1/8 is 0
write 1.0/8 instead
You're a lifesaver thanks ne555!
Topic archived. No new replies allowed.