first commit

This commit is contained in:
2026-03-17 17:34:34 +01:00
commit 45fc1ff5c0
9 changed files with 358 additions and 0 deletions
+68
View File
@@ -0,0 +1,68 @@
<!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>