Thread: simplifing fractions part 3

  1. #1

    Unhappy simplifing fractions part 3

    this is incredibly sad that im having this much trouble with this. but im gettin the idea here.... i was tryin to go about the problem using jus loops... so far everyone has told me to use gcd (which im not really familiar with.. er rather havent learned yet) but this is the code.. that i think Nick sent::

    int gcd(int a, int b)
    int r;

    while (b != 0)
    r = a % b;
    a = b;
    b = r;

    return a;

    i understand this code fer the most part.. but im confused on what variables you are asking the user to input and where you put your "cout <<" to return there answer... like i said, im literarlly just starting to learn c++ and its hard to incorporate a small line of code. all i really want to do is understand this, so if anyone could try to explain how that code ties in with the rest of the problem id be grateful. thanks everyone.

    *any new viewers :: problem = tryin to simplipy a fraction entered by the user *

  2. #2
    That is not code to do it in loops. That is a function called GDC to find the gdc of a freaction. The cout and input would be done in another part of the program...then the two numbers are passed to the function you have there...gdc().

  3. #3
    Registered User
    Join Date
    Dec 2001
    cin >> numerator;
    cin >> denominator;
    int div;
    if(numerator > denominator)
       div = gcd(numerator, denominator);
       div = gcd(denominator, numerator);
    cout << numerator << "/" << denominator << " can be simplified to " << numerator / div << "/" << denominator / div << endl;
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get a part of a string from a point onwards
    By pseudonoma in forum C Programming
    Replies: 2
    Last Post: 03-22-2008, 04:09 PM
  2. Replies: 9
    Last Post: 07-11-2006, 04:28 AM
  3. Can someone look over my code? part 2
    By brooklyn in forum C++ Programming
    Replies: 10
    Last Post: 04-18-2006, 06:33 AM
  4. Suspicious Pointer Conversion
    By mr_spanky202 in forum C Programming
    Replies: 35
    Last Post: 04-11-2003, 12:35 PM