In your code, N
, D1
, D2
, D3
, all are int
s, so the calculation
(D1*100 + D2*10 + D3 + N) / 2;
is performed as integer arithmetic and later the result is being promoted to double
. So, the result is just a double
representation of an int
value.
To enforce a floating point arithmatic, either
- Change the operand data type(s) to
double
or float
.
- Cast at least one operand to
float
.