I have code to compare two fraction classes, my class operators is below
// Equal to (==)
bool Fraction::operator == (const Fraction &fraction){
if (static_cast<double>(numerator / denominator) == static_cast<double>(fraction.numerator / fraction.denominator)){
return true;
} else {
return false;
}
} // End of == operator
.
.
.
. // And so on for all other comparisons
However my output returns the (==), (<=) and (>=) operators, saying that they are all true.
In my main()
// EQUAL TO
if (fraction1 == fraction2){
cout << fraction1.toString() << " is equal to " << fraction2.toString() << "." << endl;
}
.
.
. // And so on...
I have also tried if (fraction1.operator==(fraction2)){
instead of if (fraction1 == fraction2)
but they both return the same thing. I stuck on this, could there be something wrong with my logic? I can post more code if needed. Thanks!
edit: static_cast should be to a double. The numerators and denominators are integers and in my setter and getter methods they are integers.