Help reducing Fractions

Hello,
I am beginning to learn how to program and am just wondering how to reduce fractions. I think you're supposed to use a for loop but I don't know the for loop statement or the body of the loop. My variables I have so far that are needed are unsimplen for the un-simplified numerator, unsimpled for the un-simplified denominator, simplen for the simplified numerator, and simpled for simplified denominator. If doing this involves a function or structure, just tell me as I don't know how to program those yet. Thanks in advance.
Can you show us your code so we know what you have so far?
Well I could but its about 600 lines long and most of those lines have nothing to do with what I'm trying to figure out. Do you still want me to post it?
Maybe paste a code snippet of what you've tried so far, and what hasn't worked.
for (counter = unsimplen; counter > 0; counter--)
{
remainder = unsimplen % unsimpled;
}
quotient = unsimplen / unsimpled;

if (remainder == 0)
{
simplen = unsimplen / quotient;
simpled = unsimpled / quotient;
}

I tried this and it didn't work, it gave me random numbers when I tried to output it.
It wasn't a horrible try, but a little too simplistic. Also converting, and then going back and converting again isn't always the best way. Here is something that should work for you, I tested a few numbers and they were always right so give it a shot and let me know how it works for you.
1
2
3
4
5
   for (int i = unsimplen; i > 0; i --)
      if ((unsimplen % i == 0) && (unsimpled % i == 0)) {
         unsimplen /= i;
         unsimpled /= i;
      }
What would I output, i or unsimplen?
For what? The quotient? You can implement that yourself, it's as simple as adding one line.
Alright thanks a lot, I got it to work.
Topic archived. No new replies allowed.