In: Computer Science
Develop a routine to convert Celcius
to Fahrenheit. Have a form pass the values and a parm indicating
what time of conversion is taking place. Use a function (if
possible). Return the correct value.
Here is the formula: C = (F - 32) * 5/9
hw8.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title></head> <body> <p>Convert Temp</p> <form id="form1" name="form1" method="get" action="hw8.php"> <table width="300" border="1"> <tr> <td width="122">Enter Temp </td> <td width="168"><label> <input name="temp" type="text" id="temp" size="6" maxlength="8" /> </label></td> </tr> <tr> <td>Convert to >>> </td> <td><p> <label></label> <label> <input name="type" type="radio" value="f" checked="checked" /> Fahrenheit</label> <br /> <label> <input type="radio" name="type" value="c" /> Celcius</label> <br /> <br /> </p></td> </tr> <tr> <td> </td> <td><label> <input type="submit" name="Submit" value="Submit" /> </label></td> </tr> </table> </form> <p><a href="index.htm">return</a></p> </body> </html>
hw8.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <p>Temperature Conversion</p> <p> You converted Fahrenheit to 32 Celcius<br></p> <p><a href="hw8.html">return</a></p> </body> </html>
Hi,
I have done this script as Temperature Conversion Calculator.this convert Celsius to Fahrenheit and vise versa.
Below is script:
HTML form:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title></head>
<body>
<p>Convert Temp</p>
<form id="form1" name="form1" method="POST" action="hw8.php">
<table width="300" border="1">
<tr>
<td width="122">Enter Temp </td>
<td width="168"><label>
<input name="temp" type="text" id="temp" size="6" maxlength="8" />
</label></td>
</tr>
<tr>
<td>Convert to >>> </td>
<td><p>
<label></label>
<label>
<input name="type" type="radio" value="f" checked="checked" />
Fahrenheit</label>
<br />
<label>
<input type="radio" name="type" value="c" />
Celcius</label>
<br />
<br />
</p></td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="submit" name="Submit" value="Submit" />
</label></td>
</tr>
</table>
</form>
<p><a href="index.html">return</a></p>
</body>
</html>
PHP Script:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$temp = $_POST["temp"];
$type = $_POST["type"];
$fr = 0;
if($type=="c"){
$fr = ($temp - 32)/1.8;
}
else{
echo
$fr = ($temp*1.8)+32;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Temperature Convertor</title>
</head>
<body>
<p>Temperature Conversion</p>
<?php if($type=="c"){
?>
<p>You converted Fahrenheit to Celsius : <?php echo $fr ?><br></p>
<?php
}
else{
?>
<p>You converted Celsius to Fahrenheit : <?php echo $fr ?><br></p>
<?php
}
?>
<p><a href="index.html">return</a></p>
</body>
</html>
Output screen:
1. Celsius to Fahrenheit :
2. Fahrenheit to Celsius
Thanks