Yeah that works but the output is incorrect. He was doing modulus because that is one way to look at the problem.
Centf will read the correct value because it is being cast as an integer.
Centi will not because you need to subtract the number of feet*cent_per_foot from the number of total centimeters, and then compute the inches.
In other words, assuming everything was an integer:
feet = centimeters * FEET_PER_CENTIMETER;
inches = (centimeters % CENTIMETERS_PER_FOOT) * INCHES_PER_CENTIMETER;
This, of course, does not work because modulus is an integer only arithmetic operation.
You could define your constants more appropriate like I did above like the following:
const double FEET_PER_CENTIMETER = 0.0333;
const double INCHES_PER_CENTIMETER = 0.4;
const double CENTIMETERS_PER_FOOT = 1. / FEET_PER_CENTIMETER;
then
Now, floor() is doing the same thing as truncate or explicit integer cast, but it is better 'style' to use floor or ceil than a cast:
centf = floor(cent * FEET_PER_CENTIMETER);
centi = floor((cent - floor(centf * CENTIMETERS_PER_FOOT)) * INCHES_PER_CENTIMETER);
As I say, though, you can just leave off 'floor()' and use '(int)', or just trust the compiler to do the cast implicitly.