Skip to content

Commit

Permalink
Complete code PHP calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorJF authored Feb 22, 2024
1 parent 553f1ed commit d85bb3d
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
67 changes: 67 additions & 0 deletions PHP CALC/css/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
h1{
font-family: 'Gotham';
display: flex;
justify-content: center;
align-items: center;
}

h3{
font-family: 'Gotham';
}

.calculator {
max-width: 300px;
margin: auto;
padding: 20px;
background-color: #ffffff;
border-radius: 8px;
box-shadow: 0 0 40px 20px rgba(0, 0, 0, 0.1);
text-align: center;
}

.calculator input,
select {
width: 80%;
padding: 10px;
margin-bottom: 10px;
border: 1px solid #cccccc;
border-radius: 4px;
}

button {
padding: 10px 20px;
background-color: #8a2be2;
color: #ffffff;
border: none;
border-radius: 4px;
cursor: pointer;
}

button:hover {
background-color: #9932cc;
}



.resultado{
font-family: 'Gotham';
font-weight: bold;
display: flex;
justify-content: center;
align-items: center;
max-width: 300px;
margin: auto;
padding: 20px;
background-color: #ffffff;
border-radius: 8px;
box-shadow: 0 0 40px 20px rgba(0, 0, 0, 0.1);
text-align: center;
}

p{
font-family: 'Gotham';
font-weight: bold;
display: flex;
justify-content: center;
align-items: center;
}
38 changes: 38 additions & 0 deletions PHP CALC/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="pt-br">

<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">
<link rel="stylesheet" href="css/styles.css">
<title>Calculadora PHP</title>
</head>
<body>
<div>
<h1>CALCULDORA</h1>
</div>
<div class="divc">
<form class="calculator" action="operacoes.php" method="get">
<h3>Calculadora Quatro Operações</h3>
<div class="caixatexto">
<input type="text" id="number1" name="number1" placeholder="Number 1" />
<input type="text" id="number2" name="number2" placeholder="Number 2" />
</div>
<select id="operacao" class="select" name="operacao">
<option> </option>
<option value="Soma">Soma</option>
<option value="Subtracao">Subtracao</option>
<option value="Divisao">Divisao</option>
<option value="Multiplicacao">Multiplicacao</option>
<option value="Raiz">Radiciação</option>
<option value="Potencia">Potênciação</option>
</select>
<button type="submit" class="calcular">Calcular</button>
</form>
</div>
</body>
</html>
58 changes: 58 additions & 0 deletions PHP CALC/operacoes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html lang="pt-br">

<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">
<link rel="stylesheet" href="css/styles.css">
<title>Calculadora PHP</title>
</head>

<body>

<?php
$operacao = $_GET["operacao"];
$number1 = $_GET["number1"];
$number2 = $_GET["number2"];
$resultado = [];

switch ($operacao) {
case 'Soma':
$resultado = $number1 + $number2;
break;
case 'Subtracao':
$resultado = $number1 - $number2;
break;
case 'Divisao':
if ($number2 == 0) {
echo "<p>Não é possível dividir por 0.</p>";
} else {
$resultado = $number1 / $number2;
}
break;
case 'Multiplicacao':
$resultado = $number1 * $number2;
break;
case 'Potencia':
$resultado = $number1 ** $number2;
break;
case 'Raiz':
$resultado = $number1 ** (1 / $number2);
break;
default:
echo "<p>Insira os valores.</p>";
}

?>

<div class="resultado">
<p>Resultado:
<?php echo $resultado; ?>
</p>
</div>
<p><a href="index.php">Voltar</a></p>

</body>

</html>

0 comments on commit d85bb3d

Please sign in to comment.