Need help with cnverting temperature code.

I need help converting my temperature from either Fahrenheit to Celsius and vice versa.

Please someone look over my code.

[php]

<?php function ftoc($fahrenheit) { $celsius = ($fahrenheit - 32) * 5/9; } function ctof($celsius){ $fahrenheit = ($celsius * 5/9) + 32; } ?>

[/php]

Temperature Conversion

Degrees: Celsius Fahrenheit

[php]<?php
function ftoc($fahrenheit) {
$celsius = ($fahrenheit - 32) * 5/9;
}
function ctof($celsius){
$fahrenheit = ($celsius * 5/9) + 32;
}

?>

Temperature Conversion

Degrees: Celsius Fahrenheit

[/php]

Your not returning any value in the functions. Add return $celsius; or return $fahrenheit;

Hello angoods0544, In your code two mistake 1.) form structure is not proper but it dose not effect your output. 2.) function that your using not returning any value when it is call.

You can do two thing
1.) Replace current function with below function
[php]
function ftoc($fahrenheit) {
$celsius = ($fahrenheit - 32) * 5/9;
return $celsius;
}
function ctof($celsius){
$fahrenheit = ($celsius * 5/9) + 32;
return $fahrenheit;
}
[/php]

2.) you can use below code(script) too.

[php]

<?php if($REQUEST_METHOD == 'POST') { function ftoc($fahrenheit) { $celsius = round(($fahrenheit - 32) * 5/9 , 2); echo $fahrenheit.' fahrenheit Degrees='.$celsius.' Degrees'; } function ctof($celsius) { $fahrenheit = round(($celsius * 5/9) + 32, 2); echo $celsius.' celsius Degrees = '.$fahrenheit.' Degrees' } if($_POST['scale'] == 'celsius') { ftoc($_POST['temperature']); } if($_POST['scale'] == 'fahrenheit') { ctof($_POST['temperature']); } } ?>

Temperature Conversion

Degrees: Celsius Fahrenheit

[/php]

I hope this will helpful for you.
Reply your feedback
SR

Sponsor our Newsletter | Privacy Policy | Terms of Service