C#C
C#3y ago
45 replies
Dinny

Overloading "+" operator

I am adding fractions together and need to overload the plus operator, but I keep running into an error while I am building the code. Before even adding them together, he wants us to find the GCD (greatest common denom) to simplfy the fractions down before adding them together, which is where my error arises.

private void Simplify()
{
    if (numerator == 0)
    {

        denominator = 1;
        return;

    }

    //Finding GCD for num and denom.
    uint GCD = GetGCD((uint)Math.Abs(numerator), denominator);
    numerator /= (int)GCD;
    denominator /= GCD;
}


I get an error under "denominator" after the "Math.Abs(numerator)" and when dividing the denominator by the GCD
Was this page helpful?