0

hey guys I'm a newb to this C++ programming and I need help. I've made a non-recursive GCD C++ code, but i was having problems with the algorithm. Can someone help please?

```
import java.util.Scanner;
public class GCD
{
public static int GCD;
public static int div;
public static int remainder = 1;
public static void main(String [] args)
{
int num2;
Scanner keyboard = new Scanner(System.in);
do{
//Prompting for first number
System.out.println("Enter the first number: ");
int num1 = keyboard.nextInt();
//Exit
if(num1 <= 0)
{
System.exit(0);
}//Ending of if
//Prompting for second number
System.out.println("Enter the second number: ");
num2 = keyboard.nextInt();
div = num1 / num2;
remainder = num1 % num2;
if (num1 < num2)
{
div = num1;
num1 = num2;
num2 = div;
}
while(remainder != 0)
{
div = num1 / num2;
remainder = num1 % num2;
num1 = num2;
num2 = remainder;
}
num2 = GCD;
System.out.println("The GCD is: " + GCD);
} while (GCD >= 0);
}//Ending bracket of method main
}//Ending bracket of class
```