Thread: Simplify Fraction Help

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    16

    Simplify Fraction Help

    hi, i wrote this function to help me reduce a fraction but i can't seem to get it to work. the errors say

    invalid use of member (did you forget the `&' ?)
    expected `)' before ':' token

    both occor at the line i starred.

    Code:
    void Rational::simplify(Rational rational)
    {
         int x;
       *****  for (x=2; x <= ((num>den) ? num :den); x++)   *****
         {
             if (num%x==0 && den%==0)
             {
                          num=(num/x);
                          den=(den/x);
                          x--;
             }
         }            
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    I believe the commonly used approach here is to find the greatest common divisor, then divide both the numerator and denominator by the GCD. What's with the unused Rational parameter?

    Anyway, you might want to post the smallest and simplest program that demonstrates the error.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with fraction division function
    By trippedwire in forum C++ Programming
    Replies: 6
    Last Post: 10-24-2004, 11:38 AM
  2. A tragedy!
    By Aakash Datt in forum C++ Programming
    Replies: 4
    Last Post: 05-01-2003, 06:57 PM
  3. Overloading insertion and extraction problem
    By Curwa in forum C++ Programming
    Replies: 1
    Last Post: 01-15-2003, 09:20 PM
  4. Help with Fraction class
    By cheeisme123 in forum C++ Programming
    Replies: 0
    Last Post: 06-04-2002, 07:48 AM
  5. reducing a fraction
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 03-13-2002, 08:56 PM