Applied Programming/Variables/PHP
variables.php
edit<?php
// This program converts a Fahrenheit temperature to Celsius.
//
// Input:
// Fahrenheit temperature
//
// Output:
// Fahrenheit temperature
// Celsius temperature
//
// Example:
// Enter Fahrenheit temperature:
// 122
// 122 Fahrenheit is 50 Celsius
//
// References:
// * http://www.mathsisfun.com/temperature-conversion.html
// * http://php.net/manual/en/features.commandline.io-streams.php
// * https://stackoverflow.com/questions/481466/php-string-to-float
$temperature_difference = 32;
$temperature_ratio = 5 / 9;
echo ("Enter Fahrenheit temperature:");
$fahrenheit = (float) rtrim(fgets(STDIN));
$celsius = ($fahrenheit - $temperature_difference) * $temperature_ratio;
echo $fahrenheit . " Fahrenheit is " . $celsius . " Celsius!";
?>
Try It
editCopy and paste the code above into one of the following free online development environments or use your own PHP compiler / interpreter / IDE.