Ejemplo switch case Calculando Grados Fahrenheit PHP
En este ejemplo de php utilizaremos Las Formulas de conversión de incrementos
de grados Fahrenheit Celsius y Kelvin para calcular el valor de temperatura Introducido utilizando el switch.
Formulas:
Fahrenheit a Celsius C =(F-32)*5/9
Fahrenheit a Kelvin K = (F-32)*5/9 +273
Celsius a Fahrenheit F =C*9/5+32
Celsius a Kelvin K=C+273
Kelvin a Fahrenheit F= (k-273)9/5+32
Kelvin a Celsius C=K-273
Codigo:
<html>
<head>
<title>Conversiones</title>
</head>
<body>
Calculando Grados Fahrenheit php
<form method="post" action="Grados.php">
Seleccione la conversion que quiere haser:
<p>accion<br>
<select name="accion">
<option value="Fahrenheit a Celsius">Fahrenheit a Celsius</option>
<option value="Fahrenheit a Kelvin">Fahrenheit a Kelvin </option>
<option value="Celsius a Fahrenheit">Celsius a Fahrenheit</option>
<option value="Celsius a Kelvin">Celsius a Kelvin</option>
<option value="Kelvin a Fahrenheit">Kelvin a Fahrenheit</option>
<option value="Kelvin a Celsius">Kelvin a Celsius</option>
</select></p>
<br>Ingrese valor a convertir<br>
<input type="text" name="numero">
<br>
<input type="submit" value="calcular">
</form>
<?php
if ($_REQUEST[accion]!=""){
switch ($_REQUEST[accion]) {
case "Fahrenheit a Celsius":
//Fahrenheit a Celsius C =(F-32)*5/9
$C =($_REQUEST[numero]-32)*5/9;
echo "<h2>".$C." C</h2>";
break;
case "Fahrenheit a Kelvin":
//Fahrenheit a Kelvin K = (F-32)*5/9 +273
$K = ($_REQUEST[numero]-32)*5/9 +273;
echo "<h2>".$K." K</h2>";
break;
case "Celsius a Fahrenheit":
//Celsius a Fahrenheit F =C*9/5+32
$F =((1*$_REQUEST[numero]*9)/5)+32;
echo "<h2>".$F." F</h2>";
break;
case "Celsius a Kelvin":
//Celsius a Kelvin K=C+273
$K=$_REQUEST[numero]+273;
echo "<h2>".$K." K</h2>";
break;
case "Kelvin a Fahrenheit":
//Kelvin a Fahrenheit F= (k-273)9/5+32
$F=($_REQUEST[numero]-273)*9/5+32;
echo "<h2>".$F." F</h2>";
break;
case "Kelvin a Celsius":
//Kelvin a Celsius C=K-273
$C=$_REQUEST[numero]-273;
echo "<h2>".$C." C</h2>";
break;
default: echo "error";;
}
} else { echo "<h2>Accion no valida</h2>"; }
?>
</body>
</html>
Descargar Ejemplo:

Comentarios
Publicar un comentario