How can I make this function display "-1" as the GCD if 0 or a Negative number is entered. I've tried so many ways, but I can not figure this out! Any help is appreciated!
#include <iostream>
#include <cmath>
using namespace std;
int GCD(int a, int b);
int main() {
while(true)
{
int a, b;
cout<<"Please enter two numbers:";
cin>>a>>b;
cout<<"The greatest common divisor of the numbers is:" << GCD(a,b) << endl;
break;
}
return 0;
}
int GCD(int a, int b) {
while(true)
{
int r;
r=(a%b);
if(0 == r)
break;
b = r;
}
return b;
}