double type work like int

hello all ,

i have double type lets say it called "a" ,
when i do some calculation like a=10/4;
and printout the variable its print the number 2 and not 2.5
when i declare a=2.5 its print out 2.5 .

im using visual studio 2010 pro , platform Win32 .

anyone can tell me what im doing wrong ?

thanks .
Last edited on
10/4 is an integer division, thus it result will be an integer
you need to make one of the operands a double to get a double as result
eg: 10./4 the dot makes it a double, you can also write 10.0/4 or do the same to 4
thanks ,
and if i have parameter and i want to divide it by 4 , how can i do this ?
lets say :
int a=10;
double d;
d=a ? 4
(hope you understand me -)

Last edited on
ok i understand it ,
i do cast to double and then divide it

thank for your fast responde , great site .
Topic archived. No new replies allowed.