Wrong calculation

I am writing a program that asks for the user's height, weight, and age, and then computes clothing sizes according to the formulas.

However, the division and multiplication seems to be a little off. I think I passed all of the variables, but there is still a problem.

#include <iostream>
#include <cmath>
#include <cstdlib>

using namespace std;

double hatsize(double weightPar, double heightPar);
double jacketsize(double weightPar, double heightPar);
double waistsize(double weightPar);

int main()
{
double height, weight, age;
cout << "Height: ";
cin >> height;
cout << "Weight: ";
cin >> weight;
cout << "Age: ";
cin >> age;
cout << "Your recommended hat size is ";
hatsize(height, weight);
cout << "\n";
cout << "Your recommended jacket size is ";
jacketsize(height, weight);
cout << "\n";
cout << "Your recommended waist size is ";
waistsize(weight);
return 0;
}
double hatsize(double weightPar, double heightPar)
{
double hat, weight, height;
hat = ((weight/height)*2.90);
cout << hat;
return (hat, height, weight);
}
double jacketsize(double weightPar, double heightPar)
{
double jacket, weight, height;
jacket = ((height*weight)/288.0);
cout << jacket;
return (jacket, weight, height);
}
double waistsize(double weightPar)
{
double waist, weight;
waist = (weight/5.7);
cout << waist;
return (waist, weight);
}
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
#include <iostream>

double hatsize( double weight, double height );
double jacketsize( double weight, double height );
double waistsize( double weight );

int main()
{
    double height ;
    std::cout << "Height: ";
    std::cin >> height;

    double weight ;
    std::cout << "Weight: ";
    std::cin >> weight;

    if( height > 0 && weight > 0 )
    {
        std::cout << "Your recommended hat size is " << hatsize( weight, height ) << '\n'
                  << "Your recommended jacket size is " << jacketsize( weight, height ) << '\n'
                  << "Your recommended waist size is " << waistsize(weight) << '\n' ;

    }
}

double hatsize( double weight, double height ) { return weight/height * 2.90 ; }

double jacketsize( double weight, double height ) { return height*weight / 288.0 ; }

double waistsize( double weight ) { return weight / 5.7 ; }
There are return statements, one in each function.

For example: double hatsize( double weight, double height ) { return weight/height * 2.90 ; }

We could also write an equivalent, more verbose vrsion:
1
2
3
4
5
double hatsize( double weight, double height ) 
{ 
    const double hsize = weight/height * 2.90 ;
    return hsize ;
}
Topic archived. No new replies allowed.