81 lines
2.7 KiB
PHP
81 lines
2.7 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
|
<title>Einsendeaufgabe 2</title>
|
|
<?php
|
|
require("meinefunktionen.inc.php");
|
|
?>
|
|
</head>
|
|
<body>
|
|
|
|
<h1>Rechner</h1>
|
|
<?php
|
|
if(is_numeric($_POST["zahl1"]) && is_numeric($_POST["zahl2"])) {
|
|
|
|
if(isset($_POST["zahl1"])){
|
|
|
|
switch($_POST["operator"]){
|
|
case "+":
|
|
$ergebnis = addiere($_POST["zahl1"], $_POST["zahl2"]);
|
|
break;
|
|
case "-":
|
|
$ergebnis = subtrahiere($_POST["zahl1"], $_POST["zahl2"]);
|
|
break;
|
|
case "*":
|
|
$ergebnis = multipliziere($_POST["zahl1"], $_POST["zahl2"]);
|
|
break;
|
|
case "/":
|
|
$ergebnis = dividiere($_POST["zahl1"], $_POST["zahl2"]);
|
|
break;
|
|
default:
|
|
echo "<p><b>Bitte eine Rechenoperation angeben!</b></p>\n";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
if(isset($_POST["zahl1"])){
|
|
echo "Bitte Nummern eingeben";
|
|
}
|
|
}
|
|
?>
|
|
<?php
|
|
if(isset($ergebnis)){
|
|
echo "<p><b> {$_POST["zahl1"]} {$_POST["operator"]} {$_POST["zahl2"]} = $ergebnis</b></p>\n";
|
|
}
|
|
|
|
?>
|
|
|
|
<form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post">
|
|
<p>
|
|
Bitte geben Sie in den Feldern die Daten ein:
|
|
</p>
|
|
<p>
|
|
<label for="zahl1">Zahl 1</label>
|
|
<input type="text" name="zahl1" id="zahl1" placeholder="Zahl 1" required autofocus>
|
|
</p>
|
|
<p>
|
|
<label for="zahl2">Zahl 2</label>
|
|
<input type="text" name="zahl2" id="zahl2" placeholder="Zahl 2" required>
|
|
</p>
|
|
<p>
|
|
<li><input type="radio" name="operator" id="addieren" value="+">
|
|
<label for="addieren">+</label></li>
|
|
<li><input type="radio" name="operator" id="subtrahieren" value="-">
|
|
<label for="subtrahieren">-</label></li>
|
|
<li><input type="radio" name="operator" id="multiplikation" value="*">
|
|
<label for="multiplikation">*</label></li>
|
|
<li><input type="radio" name="operator" id="division" value="/">
|
|
<label for="division">/</label></li>
|
|
</p>
|
|
<p>
|
|
<input type="submit" value="Berechnen">
|
|
<input type="reset" value="Zurücksetzen">
|
|
</p>
|
|
|
|
</form>
|
|
|
|
|
|
</body>
|
|
</html>
|