Robson » Little Red Book » Temperature conversion #1

Chapter 1 - Question 5

Given the temperature in degrees Fahrenheit, compute the equivilant 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 generate fahrenheit and the centigrade equivilant
   echo $fahrenheit . '  degrees Fahrenheit is ' . round($centigrade, 2) . ' degrees Centigrade';    
?>

Which produces:

25 degrees Fahrenheit is -3.89 degrees Centigrade

Log

© 2004-17 robson | cc unless stated