The problem here is that you are creating multiple different variables with the same name.
Whenever you say "double foo;", that creates
another, separate variable named foo.
Here, you have 3 different occurances of
double stone
. One on line 23, one on line 29, and again on line 36.
What's happening is this:
line 23:
stone and pounds are local to getStoneAndPounds
only. They are not visible outside that function. You set them to 12 and 2.2, but then the function exits and the variables go out of scope. They're gone forever.
Basically the function does nothing. Just sets some values, but then the values disappear immediatley.
line 29, 30:
this creates global variables assigns them. These variables are visible for the rest of the program below those lines
line 36:
this creates another set of variables which "hide" the global variables. Now when you print stone and pounds in main, you are printing the local variables, and not the global variables
FURTHERMORE:
This function also does nothing:
1 2 3 4
|
void weight :: setKilograms (double g)
{
g * 1000;
}
|
You're taking g and multiplying it by 1000, but you're not doing anything with the result.
THE SOLUTION:
Notice how your weight class has a 'w' member. This member is to record the weight. setKilograms is probably supposed to modify this w member.
getStoneAndPounds is probalby supposed to change stone and pounds depending on the value of 'w'.
Note that in order for getStoneAndPounds to output anything, you'll need to pass the values by reference. Change it to this:
void getStoneAndPounds(double& stone, double& pounds);
Note the '&' symbols. This means you're passing a reference to the variable, instead of making a separate copy of the variable (which was your problem before).