martes, 7 de mayo de 2013

Creacion de la calculadora


<?
if (!$_POST) {
?>
<table border="1" width="300" align="center" >
<form action= "<?$_POST?>" method=post target=marco>
<tr>
<td colspan="2" bgcolor=#09F><h1 align="center"><span style="color:#FFFFFF; font-size 3em; font-family:Segoe Print";>Calculadora</span></h1></td>
</tr>
<tr>
<td>
<input type=text name=v1 required maxlength=10 size=15 />
<input type=text name=v2 required maxlength=10 size=15 />
</td>
<td>
<iframe name=marco width=200 height=60 frameborder=0></iframe>
</td>
</tr>
<tr>
<td colspan=2 align=center>
<input type=radio name=operador value=1>Sumar</option>
<input type=radio name=operador value=2>Restar</option>
<input type=radio name=operador value=3>Dividir</option>
<input type=radio name=operador value=4>Multiplicar</option>
</td>
</tr>
<tr>
<td colspan=2 align=center>
<input type=submit value=calcular />
<input type=reset value=borrar />
</form>
</table>


<?
} else {
$v1= $_POST ['v1'];
$v2= $_POST ['v2'];
$operador= $_POST ['operador'];

switch ($operador) {
case 1:
$res = $v1 + $v2;
echo "<div align=center><span style='font-size:2em; font-family:comic sans; color:#039;'>$res</span></div>";
break;
case 2:
$res = $v1 - $v2;
echo "<div align=center><span style='font-size:2em; font-family:comic sans; color:#039;'>$res</span></div>";
break;
case 3:
if ($v1==0 || $v2==0) {
echo "Ingrese un número diferente a 0";
exit;
}
$res = $v1 / $v2;
echo "<div align=center><span style='font-size:2em; font-family:comic sans; color:#039;'>$res</span></div>";
break;
case 4:
if ($v1==0 || $v2==0) {
echo "Ingrese un número diferente a 0";
exit;
}
$res = $v1 * $v2;
echo "<div align=center><span style='font-size:2em; font-family:comic sans; color:#039;'>$res</span></div>";
break;
}
}
?>

No hay comentarios:

Publicar un comentario