Thread: divide

  1. #1
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117

    divide

    can I divide a float with another float or with an integer?

    I tried the following :
    float mean =0;
    int number = 0; //initialization... doesnt stay that way
    cout <<_" mean : " << mean/number << endl;

    and I keep getting the 2 same errors :
    stray '\302' in program
    stray '\240' in program

    what am I doing wrong?

    Luigi

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    it might be because you are dividing 0 / 0.

    edit: actually, I don't get errors with this code. Is this the whole program?

    edit_2: no errors if underscore taken out before string literal.
    Last edited by alpha; 02-03-2003 at 10:27 PM.

  3. #3
    Back after 2 years Panopticon's Avatar
    Join Date
    Dec 2002
    Posts
    262
    It should work. Dividing by 0 isn't like in math where weird stuff happens. I think a garbage result is returned.

    Why is there an underscore after cout<< ?
    I AM WINNER!!!1!111oneoneomne

  4. #4
    samurai warrior nextus's Avatar
    Join Date
    Nov 2001
    Posts
    196
    i thought that if you do put a 'f' after the number then it will be a float if you dont it be a double..so it should be like this
    Code:
    float mean = 0.0f;
    
    //instead of float mean = 0;
    Last edited by nextus; 02-04-2003 at 02:15 AM.
    nextus, the samurai warrior

  5. #5
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by Panopticon
    It should work. Dividing by 0 isn't like in math where weird stuff happens.
    Actually, very bad stuff happens. When you divide by 0 an exception is thrown, so if you don't try and catch, your program's gonna crash.

  6. #6
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    the underscore shouldnt be there..
    error slipped while I typed it..
    no I didnt cut and paste..

    second : number's value doesnt stay that way like the comment said..
    it goes up to 10..
    so the error is not 0/0..

    I dont have the whole code with me now Ill post it later when I get back home...

    In the mean time Ill try float mean = 0.0f;

    luigi

  7. #7
    samurai warrior nextus's Avatar
    Join Date
    Nov 2001
    Posts
    196
    float mean = 0.0f; isnt going to help that just makes it a float instead of a double.....
    nextus, the samurai warrior

  8. #8
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    well guess what..
    I just re-tyoed exactly the same thing and now it works!

    go wonder...

    HO WELL!!!

    Luigi
    thx all

  9. #9
    Back after 2 years Panopticon's Avatar
    Join Date
    Dec 2002
    Posts
    262
    Originally posted by Polymorphic OOP
    Actually, very bad stuff happens. When you divide by 0 an exception is thrown, so if you don't try and catch, your program's gonna crash.
    Really? I didn't know that. But i remember enterring an int divided by a 0 in my crappy calculator and a garbage result was displayed.
    I AM WINNER!!!1!111oneoneomne

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. divide by zero
    By George2 in forum C# Programming
    Replies: 17
    Last Post: 05-02-2008, 02:37 AM
  2. Divide 64bit number
    By freeindy in forum C Programming
    Replies: 4
    Last Post: 10-01-2007, 03:56 AM
  3. Divide and Conquer: array in the reverse order
    By Steamer in forum C Programming
    Replies: 11
    Last Post: 03-08-2004, 07:31 PM
  4. severe beating of divide by zero
    By muttski in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 11-22-2002, 05:54 PM
  5. Divide and Average Algorithm
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 01-25-2002, 03:30 PM