I'm trying to design a class called "Weight" which is made up of a double datatype (for the magnitude of weight) and a char for the unit. I've written out the header file and in the private section, included the data members which are
double myHeavy;
char myUnit;
My problem is, that I am trying to write a utility function in my .cpp file that will take the inputs of weight and unit, and return the converted weight (kilos to pounds or vice versa) and the other unit. My original plan was to do this:
1 2 3 4 5 6 7 8 9 10 11
|
// Definitions of Ultility Functions
double toKilos(double weight, char unit){ //converts from pounds to Kilos
myUnit = 'K';
return (weight * .4536);
}
double toPounds(double weight, char unit){ //Converts from kilos to pounds
myUnit = 'L'; //Changes unit to L for pounds
return (weight / .4536); //Returns converted weight
}
|
However, when compiling I get the following errors
15 [jason]/home/student/munoz> g++ weight.cpp driver.cpp
weight.cpp: In member function `unsigned int Weight::getHeavy() const':
weight.cpp:37: warning: converting to `unsigned int' from `const double'
weight.cpp: In function `double toKilos(double, char)':
weight.cpp:117: error: `myUnit' was not declared in this scope
weight.cpp: In function `double toPounds(double, char)':
weight.cpp:123: error: `myUnit' was not declared in this scope
weight.cpp:125:2: warning: no newline at end of file
I'm assuming its because I'm trying to alter the private function member.
Anyone have any good idea on how to do this? or perhaps an easier method? I don't suppose you can return a double and char using just one function???