logo CodeStepByStep logo

inches_to_centimeters

Language/Type: PHP basics expressions variables

Write a function named inches_to_centimeters that takes two parameters: a number of feet (ft) and a number of inches (in). The function should convert these values into centimeters and return the result. Note that there are 2.54 centimeters per inch, and 12 inches per foot.

For example, the call inches_to_centimeters(5, 11) should return 180.34 (from (5 * 12 + 11) * 2.54).

If either argument passed is negative, throw an Exception with the message, "values for feet and inches must be non-negative".

Function: Write a PHP function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.