# simplifing fractions part 3

This is a discussion on simplifing fractions part 3 within the C++ Programming forums, part of the General Programming Boards category; this is incredibly sad that im having this much trouble with this. but im gettin the idea here.... i was ...

1. ## 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. 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. Code:
```cin >> numerator;
cin >> denominator;

int div;

if(numerator > denominator)
{
div = gcd(numerator, denominator);
}
else
{
div = gcd(denominator, numerator);
}

cout << numerator << "/" << denominator << " can be simplified to " << numerator / div << "/" << denominator / div << endl;```