I'm having trouble with creating a program that calculates the greatest common divisor between two numbers. I would greatly appreciate some help.
Code:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
double gcd ( int x, int y );
int main()
{
int a;
int b;
// allow the five sets of numbers to be input
for ( int j = 1; j <= 5; ++j ) {
cout << "Enter two integers: ";
cin >> a >> b;
cout << "The greatest common divisor of " << a
<< " and " << b << " is "
<< gcd ( a, b ) << "\n\n";
} // end for
return 0;
} // end main
// function gcd definition
double gcd( int x, int y )
{
int greatest = 1;
for ( int i = 2; i <= ( ( x < y ) ? x : y ); ++i );
if 0 = ( x % i ) + ( y % 1 );
greatest = i;
return greatest;
} // end function gcd