Division result is always zero [duplicate]

because in this expression

t = (1/100) * d;

1 and 100 are integer values, integer division truncates, so this It’s the same as this

t = (0) * d;

you need make that a float constant like this

t = (1.0/100.0) * d;

you may also want to do the same with this

k = n / 3.0;

Leave a Comment