Simbolos numericos php

En este ocasión mostrare un ejemplo de php en el cual
se introducirán 2 números para mostrar con ellos
el uso de los 4 símbolos numéricos principales
los cuales son:

+ para hacer sumas

como ser 2+2 = 4

- para restas

99-1 = 98

* para multiplicar

5*4 = 20

/ para dividir

99/3 = 33


aqui el codigo:

En la siguiente pagina introduciremos los valores
Pagina3:
 <html> 
  <head> 
  <title>Ingresando valor</title> 
  </head> 
  <body>
  <br> Introduce los valores <br>
  <form method="post" action="pagina4.php" >
  <br> Ingrese el primer numero<br>
  <input type="text" name="num1">
  <br>
  <br>Ingrese el segundo numero<br>
  <input type="text" name="num2">
  <br>
  <p>accion<br>
<select name="accion">
<option value="suma">suma</option>
<option value="resta">resta</option>
<option value="multiplicacion">multiplicacion</option>
<option value="division">division</option>
</select></p>
<input type="submit" value="confirmar">
</form>
</body> 
</html>


en la siguente calcularemos


Pagina4:
 <html> 
  <head> 
  <title>Capturando valor</title> 
  </head> 
  <body>  
<?php 
#if(isset($_REQUEST['aa']))
#{
 #echo'si existe: '.$_REQUEST['aa'];
#}
if($_REQUEST['accion'] == "suma"){
$tot;
$tot = $_REQUEST['num1'] + $_REQUEST['num2'];
echo "Total de la suma: ".$tot; 
 
}
else if($_REQUEST['accion'] == "resta"){
$tot;
$tot = $_REQUEST['num1'] - $_REQUEST['num2'];
echo "Total de la resta: ".$tot; 
 
} 
else if($_REQUEST['accion'] == "multiplicacion"){
$tot;
$tot = $_REQUEST['num1'] * $_REQUEST['num2'];
echo "Total de la multiplicacion: ".$tot; 
 
} 
else if($_REQUEST['accion'] == "division"){
$tot;
try{
$tot = $_REQUEST['num1'] / $_REQUEST['num2'];
echo "Total de la division: ".$tot; 
}
catch(Exception $e){
 echo "Error";
 }

} 
 
else {echo "accion no valida";}
 
  ?>
<form method="post" action="pagina3.php">
<input type="submit" value="regresar" />
</form>
</body> 
</html> 



Descargar ejemplo


Comentarios

Populares

Buscar en este blog