Calculadora en php html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>operaciones basicas</title>
    <link href="index.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <script src="index.js"></script>
    calculadora <br>
    <form action="resultado.php" method="post">
      ingrese primer numero <br>
      <input type="text" name="num1" />
      <select name="ope">
        <option value="+">+</option>
        <option value="-">-</option>
        <option value="*">*</option>
        <option value="/">/</option>
      </select>
  <br> ingrese el segundo numero <br>
  <input type="text" name="num2"/>
  <input type="reset" value="Borrar"/>
   <input type="submit" value="Calcular ya"/>
  <?php
  if ($_POST["num1"] != "" and
      $_POST["num2"] != "" )
     {$op=$_POST["ope"];
       $n1=$_POST["num1"];
       $n2=$_POST["num2"];
      switch($op)
       { case"+": echo ($sum=$n1+$n2);break;
         case"-": echo ($res=$n1+$n2);break;
         case"*": echo ($mul=$n1+$n2);break;
         case"/": echo ($divi=$n1+$n2);break;
       
         }
     }
   
  else
  {
     echo ("debe ingresar un numero");
     echo ('<br><a href="resultado"> volver</a>');
   
  }
 
 ?>
 
   
</form>
</body>
</html>

Share this

Related Posts

Previous
Next Post »