Jump to content

advice needed


Go to solution Solved by Strider64,

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

  • Solution

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. 

Edited by Strider64
  • Like 1
Link to comment
https://forums.phpfreaks.com/topic/294302-advice-needed/#findComment-1504510
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.