446,190 Members | 811 Online Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

# I need some help, Please!

 P: 8 Expand|Select|Wrap|Line Numbers #include  using namespace std;   int GCD(int a, int b) {    while(1)    {       a = a % b;          if(a ==0)             return b;          b = b % a;       if(b == 0)          return a;    } }   int LCM(int x, int y) {    int i;    if (x > Y)       for(i = y; i <= x * y; i++)       {          if (i % x == 0 && i % y ==0)             return i;       }    else       for(i = y; i <= x * y; i++)       {          if(i % x == 0 && i % y ==0)             return i;       }    return i; }   int main() {    char cAgain;    int x, y;      do    {       cout << endl << "Please enter value one: " << endl << endl;       cin >> x;       cout << endl << "Please enter value two: " << endl << endl;       cin >> y;       cout << endl << "The Greatest Commin Factor of "            << x << " and " << y << " is " << GCD(x,y) << endl;       cout << endl << "The Least Common Multiple of "             << x << " and " << y << " is " << LCM(x,y) << endl;       cout << "Would you like to calculate another? Y/y/N/n"            << endl << endl;       cin >> cAgain;    }while(cAgain == 'Y' || cAgain == 'y');      cout << endl << "Thank you for using this program." << endl;      return 0;   } There is my code. And it works except when i use the numbers -10 and zero in that order. The error says Floating Point Exception and just stops. So I was wondering what that means and how do I fix it in my code. Thanks Mar 19 '07 #1
3 Replies

 Expert 2.5K+ P: 3,652 Does this problem occur every time you include a 0, or only when you include a 0 as the second number, or only when you include -10? I suspect the error comes when you try and use modulus division by 0, but I can't be sure. Mar 19 '07 #2

 P: 8 Does this problem occur every time you include a 0, or only when you include a 0 as the second number, or only when you include -10? I suspect the error comes when you try and use modulus division by 0, but I can't be sure. It happens everytime the 0 is the second number. Mar 20 '07 #3

 Expert 2.5K+ P: 3,652 Probably division by zero, then. You should add a message informing the user that he/she cannot enter 0. If you like, you can also add some error trapping that will prevent the user from entering 0. Mar 20 '07 #4 