-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.php
More file actions
115 lines (96 loc) · 1.9 KB
/
calculator.php
File metadata and controls
115 lines (96 loc) · 1.9 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/* It was made around 2017 */
//Menu
function menu(){
printf ("CALCULADORA\n");
printf ("\n1.Sumar\n");
printf ("2.Restar\n");
printf ("3.Multiplicar\n");
printf ("4.Dividir\n");
printf ("5.Potencia\n");
printf ("6.Raiz\n");
printf ("7.Salir\n");
$option = readline("\nDigite su opcion:\n");
return( $option );
}
//Sumar
function sumar() {
$d1 = readline("Ingrese un sumando: ");
$d2 = readline("Ingrese otro sumando: ");
$r = $d1 + $d2;
printf("El resultado es: %d", $r);
}
//Restar
function restar() {
$d1 = readline("Ingrese el minuendo: ");
$d2 = readline("Ingrese el sustraendo: ");
$r = $d1 - $d2;
printf("El resultado es: %d", $r);
}
//Multiplicar
function multiplicar() {
$d1 = readline("Ingrese un factor: ");
$d2 = readline("Ingrese otro factor: ");
$r = $d1 * $d2;
printf("El resultado es: %d", $r);
}
//Dividir
function dividir() {
$d1 = readline("Ingrese el dividendo: ");
$d2 = readline("Ingrese el divisor: ");
if ( $d2 == 0 ){
printf("Syntax error");
} else {
$r = $d1 / $d2;
printf("El resultado es: %d", $r);
}
}
//Potenciar
function potencia() {
$d1 = readline("Ingrese la base: ");
$d2 = readline("Ingrese el exponente: ");
$d3=$d1;
for ( $d4=1; $d4 < $d2; $d4++ ) {
$d3=$d3*$d1;
}
printf("El resultado es: %d", $d3);
}
//Radicar
function radicar() {
printf("Introduzca el radicando: ");
$d1 = sqrt ( $d1 );
printf("El resultado es: %f", $d1);
}
//Salir
function salir(){
exit ( 0 );
}
function validar( $option ){
switch( $option ){
case 1:
sumar();
break;
case 2:
restar();
break;
case 3:
multiplicar();
break;
case 4:
dividir();
break;
case 5:
potencia();
break;
case 6:
radicar();
break;
case 7:
salir();
break;
default:
printf ("\n\nOpcion invalida");
}
}
$option = menu();
validar( $option );