x = (float)9 / 2;
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;
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.
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
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.
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
kibbles18 (08-31-2010)
x = 9.0f/2.0f
Ah we-a blaze the fyah, make it bun dem!
Use decimals when declaring floats
kibbles18 (08-31-2010)
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.
kibbles18 (08-31-2010)
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