473,327 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

I need some help, Please!

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int GCD(int a, int b)
  5. {
  6.    while(1)
  7.    {
  8.       a = a % b;
  9.          if(a ==0)
  10.             return b;
  11.          b = b % a;
  12.       if(b == 0)
  13.          return a;
  14.    }
  15. }
  16.  
  17. int LCM(int x, int y)
  18. {
  19.    int i;
  20.    if (x > Y)
  21.       for(i = y; i <= x * y; i++)
  22.       {
  23.          if (i % x == 0 && i % y ==0)
  24.             return i;
  25.       }
  26.    else
  27.       for(i = y; i <= x * y; i++)
  28.       {
  29.          if(i % x == 0 && i % y ==0)
  30.             return i;
  31.       }
  32.    return i;
  33. }
  34.  
  35. int main()
  36. {
  37.    char cAgain;
  38.    int x, y;
  39.  
  40.    do
  41.    {
  42.       cout << endl << "Please enter value one: " << endl << endl;
  43.       cin >> x;
  44.       cout << endl << "Please enter value two: " << endl << endl;
  45.       cin >> y;
  46.       cout << endl << "The Greatest Commin Factor of "
  47.            << x << " and " << y << " is " << GCD(x,y) << endl;
  48.       cout << endl << "The Least Common Multiple of " 
  49.            << x << " and " << y << " is " << LCM(x,y) << endl;
  50.       cout << "Would you like to calculate another? Y/y/N/n"
  51.            << endl << endl;
  52.       cin >> cAgain;
  53.    }while(cAgain == 'Y' || cAgain == 'y');
  54.  
  55.    cout << endl << "Thank you for using this program." << endl;
  56.  
  57.    return 0;
  58.  
  59. }
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 1082
Ganon11
3,652 Expert 2GB
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
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
Ganon11
3,652 Expert 2GB
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

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: mike | last post by:
Hello, After trying to validate this page for a couple of days now I was wondering if someone might be able to help me out. Below is a list of snippets where I am having the errors. 1. Line 334,...
5
by: John Flynn | last post by:
hi all i'm going to be quick i have an assignment due which i have no idea how to do. i work full time so i dont have the time to learn it and its due date has crept up on me .. As follows:...
5
by: TrvlOrm | last post by:
HI There, I have been struggling with JavaScript code for days now, and this is my last resort! Please help... I am trying to create a JavaScript slide show with links for Next Slide,...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only...
8
by: CM | last post by:
Hi, Could anyone please help me? I am completing my Master's Degree and need to reproduce a Webpage in Word. Aspects of the page are lost and some of the text goes. I would really appreciate it....
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
21
by: asif929 | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to...
5
by: Justin | last post by:
Here's my XML: <?xml version="1.0" ?> <AppMode Type="Network"> <CurrentFolder Path="c:\tabs"> <Tabs> <FilePath>tabs\Justin.tab</FilePath> <FilePath>tabs\Julie.tab</FilePath> *****There could...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.