One of my calculations is coming out incorrect. Please help me spot my error

This is the problem I am doing:

"Ask for user's height (in.), weight (lbs), & age (yrs); then compute sizes according to formulas:
-Hat size=(weight/height)*2.9
-Jacket size=(height*weight/288) & then adjust by adding 1/8 inch inch for each 10 yrs over age 30. NOTE: adjustment only takes place after a full 10 yrs. So, there is no adjustment for ages 30 through 39, but 1/8 inch is added for age 40
-Waist size=(weight/5.7) & then adjust by adding 1/10 inch for each 2 yrs over age 28. NOTE: adjustment only takes place after a full 2 yrs. So, there's no adjustment for age 29, but 1/10 inch is added for age 30"

Everything is coming out right except for the waist size! It seems to be adding .0n instead of .n

Please help!

*Please note, we are not allowed to use doubles*

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
#include <iostream>
#include <iomanip> 
using namespace std;

int main(int argc, char** argv) { 
    //Variables
    float height, weight;
    int age;
    float hat, jacket, waist;
    //Input
    cout<<"Please enter height in inches, weight in pounds, and age in years\n";
    cout<<"Height: ";
    cin>>height;
    cout<<"Weight: ";
    cin>>weight;
    cout<<"Age: ";
    cin>>age;
    //Calculations
    int jackAGE=(age>30?:(age%30)/10);
    hat=weight/height*2.9;
    jacket=(height*weight/288.0f)+(jackAGE*0.125f);
    int wstAGE=(age>28?:((age%28)/2));
    waist=(weight/5.7f)+(wstAGE*.10);
    //Output
    cout<<fixed<<showpoint<<setprecision(2);
    cout<<"Your hat size is: "<<hat<<" inches.\n";
    cout<<"Your jacket size is: "<<jacket<<" inches.\n";
    cout<<"Your waist size is: "<<waist<<" inches.\n";

    return 0;
}
Last edited on
For lines 19 and 22 I get,
warning: the omitted middle operand in ?: will always be 'true', suggest explicit middle operand
Also it is a bit tedious typing test data in so I haven't bothered.
You could put the code in a loop so after each trial you don't have to keep restarting the program.
Topic archived. No new replies allowed.