Hello,
Why wont the following code assign 0.5 to variable (double type):
Thanks for help!Code:unsigned int num = 1; double d = num/2;
Hello,
Why wont the following code assign 0.5 to variable (double type):
Thanks for help!Code:unsigned int num = 1; double d = num/2;
You're dividing integers, so the result will be an integer.
1 and 2 are integer literals. 1.0 and 2.0 are double literals.
As long as one of the two operands is a double, the result will be a double, so the solution is to use 2.0 instead of 2.
Thanks for explanation!