calc.php
Código PHP:
<?php
require_once('rpmcalcoper.php');
if (isset($_POST['nume1'])) {
$num1 = $_POST['nume1'];
$num2 = $_POST['nume2'];
$op = $_POST['$rgop'];
$resultado = operation($num1,$op, $num2);
}
?>
<html>
<head>
<title>Calculadora</title>
</head>
<style type="text/css">
<!--
body { font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 10px; background-color: #ffffff; }
td { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; }
input { font-family: Tahoma; font-size: 9px; }
option { font-family: Tahoma; font-size: 9px; }
-->
</style>
<body>
<form action="" method="post" name="calc">
<table width="75%" border="0">
<tr>
<td width="11%" height="118"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="nume1" type="text" id="nume1" size="15" maxlength="15">
</font></td>
<td width="5%"><div align="center"><font size="1" face="Geneva, Arial, Helvetica, sans-serif">
<strong> </strong></font>
<p>
<label>
<input type="radio" name="rgop" value="radio">
+</label>
<br>
<label>
<input type="radio" name="rgop" value="radio">
-</label>
<br>
<label>
<input type="radio" name="rgop" value="radio">
/</label>
<br>
<label>
<input type="radio" name="rgop" value="radio">
*</label>
<br>
</p>
</div></td>
<td width="11%"><div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="nume2" type="text" id="nume2" size="15" maxlength="15">
</font></div></td>
<td width="2%"><div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">=</font></div></td>
<td width="9%"><input name="resulta" type="text" id="resulta" size="12" maxlength="12" value="<?php echo $resultado; ?>"></td>
<td width="62%"><input name="realiza" type="submit" id="realiza" value="Realizar operación ..."></td>
</tr>
</table>
<div align="center"> </div>
</form>
</body>
</html>
y el de la function rpmcalcoper.php es este otro:
Código PHP:
<?php
function operation($nume1, $rgop, $nume2)
{
if ($rgop == '+'){
$result = $nume1 + $nume2;
}
elseif ($rgop == '-'){
$result = $nume1 - $nume2;
}
elseif ($rgop == '*'){
$result = $nume1 * $nume2;
}
else{
if ($nume2 = !0){
$result = $nume1 / $nume2;
}
else{
echo "La división por cero no está definida");
}
}
return $result;
}
?>