Simplify Fraction Help

This is a discussion on Simplify Fraction Help within the C++ Programming forums, part of the General Programming Boards category; hi, i wrote this function to help me reduce a fraction but i can't seem to get it to work. ...

  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
    21,794
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 08: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, 07:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21