[help] basic code

Posts 1–11 of 11 · Page 1 of 1
[help] basic code
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.
Quote Originally Posted by why06 View Post
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.
Quote Originally Posted by freedompeace View Post
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.
Quote Originally Posted by why06 View Post
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.
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
Posts 1–11 of 11 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?