Beginner's Question II
-
You are so right,the screwy code would help greatestCommonDenominator() { int gcd, same, hold1, hold2; if(iNumerator < iDenominator){ for(gcd=1;gcd
-
You are so right,the screwy code would help greatestCommonDenominator() { int gcd, same, hold1, hold2; if(iNumerator < iDenominator){ for(gcd=1;gcd
greatestCommonDenominator() { int gcd, same, hold1, hold2; if(iNumerator < iDenominator){ for(gcd=1;gcd hold1 = iDenominator / gcd; ^^^^^^^^^^ what's up with this ? Is a bit missing in the middle ? This won't compile because the for loop has no closing bracket. Does the for loop have a ; at the end of it ? If so, it won't work either. Also, if you want the for loop to take into account more than one line, they need to also be enclosed in {}. hold2 = iNumerator / gcd; if(hold1 == hold2) same = hold1; } Here is a gcd function int gcd(int m, int n) { if (m==0) return n; else return gcd( n%m, m); } Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.
-
You are so right,the screwy code would help greatestCommonDenominator() { int gcd, same, hold1, hold2; if(iNumerator < iDenominator){ for(gcd=1;gcd
-
You are so right,the screwy code would help greatestCommonDenominator() { int gcd, same, hold1, hold2; if(iNumerator < iDenominator){ for(gcd=1;gcd
Just as a guess, the division looks suspect. You are dividing two integers, which returns an integer (throwing away the remainder), and that might not be what you want. You are also comparing (iDenominator/gcd) == (iNumerator/gcd) which (assuming you change those variables to floating-point) is true only if iDenominator == iNumerator, so check your algorithm again. --Mike-- http://home.inreach.com/mdunn/ #include "buffy_sig"
-
You are so right,the screwy code would help greatestCommonDenominator() { int gcd, same, hold1, hold2; if(iNumerator < iDenominator){ for(gcd=1;gcd