The Greatest Common Denominator should return an integer which is the GCD of the two numbers passed into the function. I didnt run your code to see if it works, but the GCD fucnction looks correct, in case its not, here is a version of it that I wrote a while back
// returns the greatest common divisor of A and B
long GCD(long A, long B)
{ if( B==0 ) return A;
return GCD(B,A%B);
}
I cant really tell what the rest of your code is doing...hope this helps a little.
FYI: global variables are bad programming practice unless they are absolutely necessary. Youve got like 11...makes my head want to explode