Casting my own Fraction object to double - always becoming 1

Hello everyone!

For this program I am writing a 'Function' class to be used in a program adds and multiplies Fraction objects. It will also create a copy of one using a copy constructor and print the objects as decimals and compare them.
My program executes fine, but when I cast my Fraction objects to the overloaded double operator it always returns 1, and I cannot figure out why - I've even gone through using breakpoints to see the values as the program runs.

Here is the Fraction class declaration
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Fraction
{
  private:
	int numerator;    // integer representing the numerator of the fraction
	int denominator;  // integer representing the denominator of the fraction
  public:
	Fraction(int = 1, int = 1);	// default constructor
	Fraction(const Fraction&);  // copy constructor
	void setNumerator(int);     // prototype for set method for the numerator
	int  getNumerator();        // "" for the get method for the numerator
	void setDenominator(int);   // "" for the set method for the denominator
	int  getDenominator();      // "" for the get method for the denominator
	void printFraction();       // method to print the fraction
	Fraction operator+(Fraction &);       // prototype for overloaded addition operator
	Fraction operator*(Fraction &);       // " for overloaded multiplication operator
	bool operator==(Fraction &);          // " for overloaded equals to operator
	void operator=(Fraction &);           // " for overloaded assignment operator
	operator double();                    // conversion operator to double
};


here is the overloaded double operator defined:
1
2
3
4
5
6
Fraction::operator double()
{ // conversion
	double value;  // double representing the fraction's decimal value
	value = numerator/denominator; // value is equal to the num divided by the denom
	return(value); // return the value
}


Here is the printing:
1
2
3
4
5
6
7
8
9
10
11
12
 cout << "\n\n******** Using copy ctor ********";
	
	Fraction fractionCcopy = fractionC;
	double a = 0;
	a = fractionC;
	double b = 0;
	b = fractionCcopy;

    cout << "\n\nOriginal object using operator double is " << a;
	cout << "\nNew object using operator double is " << b;

    return fractionCcopy;    

a and b always become and output as 1 when I assign them to the fractions.

I've posted the entire program on pastebin here: http://pastebin.com/bAhiAF5a
The program output should look similar to this: http://tinypic.com/r/2vcw6u1/6

I would be very grateful for any help!
numerator/denominator is an integral expression.

So you have to cast at least one of them to double as you do the operation, see example:
http://ideone.com/tT9md
Fixed, thank you so much!
Topic archived. No new replies allowed.