0
我很新的編程,我想創建一個轉換器從攝氏度到華氏溫度到開爾文。用戶輸入他們想要在2個輸入框中轉換的值(以攝氏度爲單位),並使用循環創建一個表格。第一組數據以攝氏度輸出,但第二組數據流(華氏溫度)僅輸出一個攝氏溫度值,即攝氏溫度環中最後一個節點的轉換值。PHP(簡單):麻煩與循環
<form name="calculator" action="" method="post">
From: <input class="inputbox" type="number" name="one" value="" /><br />
<p>to</p><br>
To: <input class="inputbox" type="number" name="two" value="" /><br />
<input type="submit" class="submit" name="submit" value="Get Conversions!" />
</form>
<br>
<table border='1' cellpadding='5px'>
<tr>
<th>Degrees Celsius</th>
<?php
if ($_POST['submit']) {
$one = $_POST['one'];
$two = $_POST['two'];
}
if ($two < $one) {
echo "<p>Please put the lowest number in the first input box.</p>";
} else if ($one < (-273) OR $two < (-273)) {
echo "<p> Tempature cant go below -273 Celsius (0 kelvin), please enter higher values.</p>";
} else {
$c = $one - 1;
do {
$c++;
echo "<td>" . $c . "</td>";
} while ($c < $two);
}
?>
</tr>
<tr>
<th>Degrees Fahrenheit</th>
<?php
$f = (1.8 * $c) + 32;
do {
$c++;
echo "<td>" . $f . "</td>";
} while ($c < $two);
$k = $x - 273;
?>
</tr>
</table>