I am able to compute a wonderful greatest common factor if the number on the numerator is larger than the denomiator. If it isn't, right now I am only outputting the fraction as the user entered it.
This obviously doesn't work well. It does for fractions that don't reduce like 2/5 but ones like 4/6 I am confused on how to do.
Help is appreciated.
This obviously doesn't work well. It does for fractions that don't reduce like 2/5 but ones like 4/6 I am confused on how to do.
Help is appreciated.
Code:
int CalcGCD(int numer, int denom) {
int top = numer;
int bottom = denom;
int m = 0;
int n = 0;
//m = top/bottom;
//n = top%bottom;
int tmp(0),tmp2(0);
m = top;
n = bottom;
m = top/bottom;
n = top%bottom;
while (1) {
if (n == 0) {
return m; //m is the gcd
}
else {
//time to do it again fool!
int tmp = m/n;
int tmp2 = m%n;
n = tmp2;
}
cout << m << "\t" << n << endl;
}