Merge branch 'main' of https://grond.iut-fbleau.fr/yolou/public-html2
This commit is contained in:
@@ -1,68 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="fr">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Calculatrice simple</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Calculatrice</h1>
|
|
||||||
|
|
||||||
<?php
|
|
||||||
|
|
||||||
$resultat = "";
|
|
||||||
$op1 = "";
|
|
||||||
|
|
||||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|
||||||
$op1 = $_POST["op1"];
|
|
||||||
$op2 = $_POST["op2"];
|
|
||||||
$operation = $_POST["operation"];
|
|
||||||
|
|
||||||
// Vérification que ce sont bien des nombres
|
|
||||||
if (is_numeric($op1) && is_numeric($op2)) {
|
|
||||||
switch ($operation) {
|
|
||||||
case "+":
|
|
||||||
$resultat = $op1 + $op2;
|
|
||||||
break;
|
|
||||||
case "-":
|
|
||||||
$resultat = $op1 - $op2;
|
|
||||||
break;
|
|
||||||
case "*":
|
|
||||||
$resultat = $op1 * $op2;
|
|
||||||
break;
|
|
||||||
case "/":
|
|
||||||
if ($op2 == 0) {
|
|
||||||
$resultat = "Erreur : division par 0 !";
|
|
||||||
} else {
|
|
||||||
$resultat = $op1 / $op2;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pour utiliser le résultat comme prochaine valeur d'opérande 1
|
|
||||||
|
|
||||||
if (is_numeric($resultat)) {
|
|
||||||
$op1 = $resultat;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$resultat = "Veuillez entrer deux nombres valides.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
|
|
||||||
<form method="post">
|
|
||||||
<input type="text" name="op1" value="<?= htmlspecialchars($op1) ?>" required>
|
|
||||||
<select name="operation">
|
|
||||||
<option value="+">+</option>
|
|
||||||
<option value="-">-</option>
|
|
||||||
<option value="*">*</option>
|
|
||||||
<option value="/">/</option>
|
|
||||||
</select>
|
|
||||||
<input type="text" name="op2" required>
|
|
||||||
<input type="submit" value="Calculer">
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<?php if ($resultat !== ""): ?>
|
|
||||||
<h2>Résultat : <?= $resultat ?></h2>
|
|
||||||
<?php endif; ?>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Reference in New Issue
Block a user