Jump to content

[SOLVED] Temperature Conversion and Sides of a Triangle


NewbiePHP22

Recommended Posts

I'm new here, and to PHP as well. I would like to know two things: How to setup temp. conversion, Fahrenheit to Celsius, so that 0 through 100 F is echo'd with the Celsius conversion echo'd beside it. And, I would like to know how make a script that checks if the combined length of any two sides of a triangle is greater than the length of the third side.

 

Any help would be appreciated.

<?php

$fahrenheit = 0;
while ($fahrenheit < 100){
$F[] = $fahrenheit;
++$fahrenheit;
foreach ($F as $Celsius){
$Celsius = (($fahrenheit - 32) / 1.;
echo "$fahrenheit F ", "<--> ", round($Celsius, 1), " C<br />";
}
}

?>

 

This is what it is showing with the code I currently have:

 

1 F <--> -17.2 C

2 F <--> -16.7 C

2 F <--> -16.7 C

3 F <--> -16.1 C

3 F <--> -16.1 C

3 F <--> -16.1 C

 

However, I need it to show like this:

 

0 F <--> -17.7 C

1 F <--> -17.2 C

2 F <--> -16.7 C

3 F <--> -16.1 C

4 F <--> -15.6 C

5 F <--> -15 C

 

 

<?php

for ($fahrenheit = 0; $fahrenheit <= 100; $fahrenheit++) {
$celsius = (($fahrenheit - 32) / 1.;
echo $fahrenheit . " F <--> " . round($celsius, 1) . " C<br />";

}

?>

 

If you are unfamiliar with FOR loops, refer to this page.

 

Regarding your triangle problem, I'm pretty sure that any two sides of a triangle will always be longer than the third side (unless I've misunderstood your question).

<?php

for ($fahrenheit = 0; $fahrenheit <= 100; $fahrenheit++) {
$celsius = (($fahrenheit - 32) / 1.;
echo $fahrenheit . " F <--> " . round($celsius, 1) . " C<br />";

}

?>

 

If you are unfamiliar with FOR loops, refer to this page.

 

Regarding your triangle problem, I'm pretty sure that any two sides of a triangle will always be longer than the third side (unless I've misunderstood your question).

 

Yes, it will be. lol I just don't understand how to put that into PHP so that it checks to make sure that is always the case. And, if it's not, then it returns an error. Ideally, I would have a html form with three text-entry boxes that would do a $_GET to refer back to the php so that it checks if the values one enters would make a triangle. Sorry for not explaining that better.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.