# divide

• 02-03-2003
Luigi
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 :D
• 02-03-2003
alpha
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.
• 02-03-2003
Panopticon
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<< ?
• 02-04-2003
nextus
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;```
• 02-04-2003
Polymorphic OOP
Quote:

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.
• 02-04-2003
Luigi
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
• 02-04-2003
nextus
float mean = 0.0f; isnt going to help that just makes it a float instead of a double.....
• 02-04-2003
Luigi
well guess what..
I just re-tyoed exactly the same thing and now it works!

go wonder... :confused:

HO WELL!!!

Luigi
thx all
• 02-04-2003
Panopticon
Quote:

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.