Jump to content

advice needed


dhmyers82

Recommended Posts

Chapter 2 homework is coded. It works and that is the main thing, but I dont just want the grade, I want want to learn php and be proficent at it. Is there anything that looks wrong, Variable names, lack off comments, things out of place. All advice is welcome.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Strict//EN"
"html://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Temperature Conversion</title>
<meta http-equiv="content-type"
	content="text/html; charset=iso-8859-1" />
</head>

<body>
<h1>Fahrenheit to Celsius Conversions</h1>
<article>
<?php
	$degFahrenheit = 0;
	
	function degreeConverter ($degFahrenheit) { //Function converts F* to C*
		$degCelsius = (($degFahrenheit - 32) * 5/9);
		$returnCelsius = round ($degCelsius, 1);
		return $returnCelsius;
	}
	do {//begining of loop
	$convertCelsius = degreeConverter($degFahrenheit);
	echo "<p>$degFahrenheit degrees Fahrenheit = $convertCelsius degrees Celsius.</p>";
	++degFahrenheit;
	}
	while ($degFahrenheit <= 100);//end of loop
?>
</article>
</body>
</html>
Link to comment
https://forums.phpfreaks.com/topic/294302-advice-needed/
Share on other sites

You sure it works?

	do {//begining of loop
	$convertCelsius = degreeConverter($degFahrenheit);
	echo "<p>$degFahrenheit degrees Fahrenheit = $convertCelsius degrees Celsius.</p>";
	++degFahrenheit; // Cough Cough....
	}
	while ($degFahrenheit <= 100);//end of loop
Link to comment
https://forums.phpfreaks.com/topic/294302-advice-needed/#findComment-1504508
Share on other sites

There's really nothing wrong in how you did it for it works and that is all that matters.  :happy-04:

 

 

However, this is how I would do it:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Strict//EN"
"html://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Temperature Conversion</title>
<meta http-equiv="content-type"
	content="text/html; charset=iso-8859-1" />
</head>

<body>
<h1>Fahrenheit to Celsius Conversions</h1>
<article>
<?php
	$fahrenheit = 0;
	/* Convert Fahrenheit to Celsius */
	function fahrenheitToCelsius($fahrenheit) { 
          return round( ($fahrenheit - 32) * 5/9, 1);	
	}
	do {//begining of loop
	$celsius= fahrenheitToCelsius($fahrenheit);
	echo "<p>$fahrenheit° F = $celsius° C.</p>";
	++$fahrenheit;
	}
	while ($fahrenheit <= 100);//end of loop
?>
</article>
</body>
</html>

However, I sure everyone else here would do it a little bit differently. 

Link to comment
https://forums.phpfreaks.com/topic/294302-advice-needed/#findComment-1504510
Share on other sites

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.