ok well i uploaded a video on to youtube so that you can look at it and tell me why 9 / 2 is not outputting 4.5.
x = (float)9 / 2;
Originally Posted by why06
Not slow... no one has provided the right anser yet.
Try 4.0/9.0
C++ will usually assume integer data type when you type a number. The decimal point or "floating point" will make the compiler treat ur number as a float. Simply casting it will still only get you the same answer as kibble.
Originally Posted by freedompeace
x = (float)9 / 2;
Last I checked, 9.0, 9.0f and casting 9 as a float do the same thing. (I've never checked, but meh)
<.<
Lol. I'll let some else handle this one, I've got to go to bed. If no one gets it by tomorrow, I'll give the answer.
Originally Posted by why06
Lol. I'll let some else handle this one, I've got to go to bed. If no one gets it by tomorrow, I'll give the answer.
a bit slow lol.
Just try :
double x;
x= 9/2;
that should help
Not slow... no one has provided the right anser yet.
Try 4.0/9.0
C++ will usually assume integer data type when you type a number. The decimal point or "floating point" will make the compiler treat ur number as a float. Simply casting it will still only get you the same answer as kibble.
x = 9.0f/2.0f
Use decimals when declaring floats
If u use simple number, the answer will be a simple number. If you use a decimal number, the answer will be a decimal number.
ok ty for all who helped me and told me to use decimels, it worked. i had assumed the compiler would make x 4.5 as defualt, an because the x is an int, it would just cut off the .5 part unless floated