Robson » Little Red Book » Temperature conversion #2

Chapter 1 - Question 6

Given the temperature in degrees Centigrade, compute the equivilant Fahrenheit value.

Solution 1

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

Which produces:

71 degrees Centigrade is 159.8 degrees Fahrenheit

Log

© 2004-17 robson | cc unless stated