Robson » Little Red Book » Temperature conversion #1

Chapter 1 - Question 5

Given the temperature in degrees Fahrenheit, compute the equivalent centigrade value.

Solution 1

<?    // generate a random number, this will be the temperature in degrees fahrenheit    $fahrenheit = mt_rand(1, 100);        // this is the way to convert fahrenheit to centigrade    $centigrade = ($fahrenheit - 32) / 1.8;        // show the randomly generated fahrenheit and the centigrade equivalent    echo $fahrenheit . '  degrees Fahrenheit is ' . round($centigrade, 2) . ' degrees Centigrade';     ?>

Which produces:

85 degrees Fahrenheit is 29.44 degrees Centigrade

Log

© 2004-20 robson | cc unless stated