I need to make three lines of php code that will randomly choose fahrenheit temp between -10 and 120 degrees and display it converted to celsius. this is the code I came up with but it wont run or validate. please help <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Phpexamples</title> </head> <body> <?php echo"<p>$f equals $ rand ($c 10)."c."</p>"; echo "<p>"$c=($f-32) * (5/9);$f "</p>"; echo "<p>"$f= rand(-10,120) "<p>"; ?> <p><a href="ex2.php">Run it now</a></p> </body> </html>
Eh... what? Okay, first off, you have a link to a page - is that the same page this code is on? If so, this is... wow. So wrong. First off, that will never work, as you're blindly echoing both HTML and PHP - seriously, mate... Second, that code is complete and utter gibberish. You have undeclared variables, use "equals"... the variables are in the wrong order... Okay, if the file in the link is the same as this is run on, use the following code: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Phpexamples</title> </head> <body> <?php $f = rand(-10,120); $c = ($f-32) / 1.8; echo 'Fahrenheit: '.$f.'<br>Celcius: '.$c; ?> <p> <a href="ex2.php">Run it now</a> </p> </body> </html> PHP: