Bad results in calculating program

Hi folks,

I need to write a program that calculates a persons clothing size.

The formulas are:
Hat size = 2.9 times the weight in pounds divided by height in inches.
Jacket size (chest in inches) = height in inches times
weight divided by 288.
Waist in inches = weight in pounds divided by 4.9

Here is what I have.

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
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <iomanip>
using namespace std;

void get_data (int weight,int feet,int inches);
void show_results (float hatsize, int jacketsize, int waistsize);
float hat_size (int weight,int feet, int inches);
int jacket_size (int weight,int feet,int inches);
int waist_size (int weight);


int main()
{
	int weight, feet, inches, height, jacketsize, waistsize;
	float hatsize;
	
	cout<<"This program will get your hat, jacket, and waist sizes \n";
	get_data(weight,feet,inches);
	hat_size(weight, feet, inches);
	jacket_size(weight, feet, inches);
	waist_size(weight);
	show_results(hatsize,jacketsize,waistsize);
	
	}

void get_data (int weight,int feet,int inches)
{
	cout<<"Please enter your weight in pounds \n";
	cin>>weight;
	cout<<"Please enter your height in feet and inches \n";
	cin>>feet>>inches;
	
	
}

float hat_size (int weight,int feet,int inches)
{
	float hatsize;
	
	hatsize=2.9*weight/((feet*12))+inches;
	return hatsize;
}

int jacket_size (int weight,int feet,int inches)
{
	int jacketsize;
	
	jacketsize=((feet*12)+inches)*weight/288;
	return jacketsize;
}

int waist_size (int weight)
{
	int waistsize;
	
	waistsize=weight/4.9;
	return waistsize;
}

void show_results (float hatsize, int jacketsize, int waistsize)
{
	cout<<"Your hat size is "<<hatsize<<endl;
	cout<<"Your jacket size is "<<jacketsize<<endl;
	cout<<"Your waist size is "<<waistsize<<endl;
}


My problem is that for results I'm getting
Your hat size is 7.14662e-044
Your jacket size is 0
Your waist size is 3
no matter what i put in. Could I get some help please?
You need to pass by reference in:
void get_data (int weight,int feet,int inches)

so it should be

void get_data (int &weight,int &feet,int &inches)
What's happening is that you're taking input into copies so the values of your original variables aren't changing.
Last edited on
Hi, thanks for your speedy reply. That makes sense, and I fixed it but now the results are Your hat size is 1.4013e-045
Your jacket size is 0
Your waist size is 40
no matter what. what else is wrong?
Now you need to set your variables equal to your functions in main. Notice that your functions return values(the calculated sizes) but you're never using them. Set your hatsize etc. variables = to their respective functions.
That worked perfect, thanks a ton!
Topic archived. No new replies allowed.