Hi Everyone,

I have this code for one of my programs and I am not sure what it does. It was given to me by my professor. It is suppose to simplify fractions. But it is messing up my program. In this program we use overloaded operators and Class objects. It is a fraction calculator program.

In my code, I add, subtract, multiply and divide the fractions and that part works fine. Then the not simplified fraction (the answer not the ones being added) is sent to this function to be simplified. For some reason it is not working properly after being sent to this function.

Please can someone explain this function to me so I can better understand what this function does and how it is affecting my code?

Thanks

Code:void Rational::reduce( ) { int largest, gcd = 1; // greatest common divisor; largest = ( numerator > denominator ) ? numerator: denominator; for ( int loop = 2; loop <= largest; ++loop ) if ( numerator % loop == 0 && denominator % loop == 0 ) gcd = loop; numerator /= gcd; denominator /= gcd; }