This code should preform the euclidian algorithm. Whether or not the code does what it is supposed to is not the problem. The problem is that I will input a and b and then... nothing. I tried putting a cout statement after the user inputted a and b but that did not run either.
#include <iostream>
usingnamespace std;
int main()
{
int a = 0, b = 0; //Initial User Input
int x = 0, y = 0; //Adjusted User Input
int gcd = 0; //The Greatest Common Denominator of User's numbers.
cout << "Please enter two numbers: ";
cin >> a >> b;
//If a and b are the same the gcd is either a or b
if(a==b)
gcd=a;
//Runs if a and b are not the same
else
{
//Runs if a is larger than b
if (a > b)
{
x = b;
y = a;
}
//Runs if b is larger than a
else
{
x = a;
y = b;
}
do
{
if (y > x)
y = y - x;
elseif (x > y)
x = x - y;
} while (x != 0 && y != 0);
if ( x == 0)
gcd = y;
elseif ( y == 0)
gcd = x;
cout << "The GCD is: " << gcd;
}
}