I am having difficulty in getting the greatest common divisor working (gcd) as I have declare "a" as int and "b" as double. The reason why b is declared as double because previously b = to the squared of sum.
Here's my code for gcd:
Code:
int GCD(int a, double b)
{
int Remainder;
while( b != 0 )
{
Remainder = a % b;
a = b;
b = Remainder;
}
return a;
}
int main()
{
int x, y;
cout << "This program allows calculating the GCD\n";
cout << "Value 1: ";
cin >> x;
cout << "Value 2: ";
cin >> y;
cout << "\nThe Greatest Common Divisor of "
<< x << " and " << y << " is " << GCD(x, y) << endl;
return 0;
I have keep getting error when compling since both a and b have different variable. I can't change b as it must be double and so as a as it also must be int. What should I do to get the gcd going?