-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculadora.php
72 lines (64 loc) · 2.39 KB
/
calculadora.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--CND BOOTSTARP-->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="css/calculadora.css">
<!--CND BOOTSTARP-->
---------
<title>Calculadora</title>
</head>
<body>
<a href="index.html#section-respuestas">
<img class="home" src="img/hogar.png" alt="">
</a>
<div class="main-frame-cal">
<form action="" method="POST">
<div class="form-group">
<label for="exampleFormControlInput1">Número 1:</label>
<input type="number" name="n1" class="form-control" id="exampleFormControlInput1" placeholder="Digite Número 1">
</div>
<div class="form-group">
<label for="exampleFormControlInput2">Número 2:</label>
<input type="number" name="n2" class="form-control" id="exampleFormControlInput2" placeholder="Digite número 2">
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Seleccione la operación:</label>
<select class="form-control" name="tipo" id="exampleFormControlSelect1">
<option value="1">Suma</option>
<option value="2">Resta</option>
<option value="3">Multiplicación</option>
<option value="4">División</option>
</select>
</div>
<button type="submit" name="operar" class="btn btn-outline-info">Resultado</button>
</form>
<?php
$n1 = $n2 = $tipo = $result = 0;
if (isset($_POST['operar'])) {
$n1 = $_POST['n1'];
$n2 = $_POST['n2'];
$tipo = $_POST['tipo'];
switch ($tipo) {
case '1':
$result = $n1 + $n2;
break;
case '2':
$result = $n1 - $n2;
break;
case '3':
$result = $n1 * $n2;
break;
case '4':
$result = $n1 / $n2;
break;
}
echo "<h1>".$result."</h1>";
#echo "<script>alert(".$result.");</script>";
}
?>
</body>
</html>