1
0
Fork 0

Correction

This commit is contained in:
Ethanell 2020-10-01 08:41:35 +02:00
parent 7eb62d14ef
commit 62edb91f95
4 changed files with 75 additions and 60 deletions

View file

@ -1,3 +1,12 @@
<?php
if (isset($_GET["nb"])) {
$nb = (int)$_GET["nb"];
if ($nb < 0 and $nb > 100)
$nb = null;
} else
$nb = null;
?>
<!DOCTYPE html>
<html lang="en">
<head>
@ -7,9 +16,7 @@
<body>
<ul>
<?php
if (isset($_GET["nb"])) {
$nb = (int) $_GET["nb"];
if ($nb >= 0 and $nb <= 100)
if ($nb !== null) {
for ($i = 0; $i < $nb; $i++) { ?>
<li>Hello World !</li>
<?php }

View file

@ -1,3 +1,18 @@
<?php
$nb = null;
$name = null;
$error = false;
if (isset($_GET["nb"]) AND isset($_GET["name"])) {
$nb = (int)$_GET["nb"];
$name = htmlspecialchars($_GET["name"]);
if ($nb < 0 or $nb > 100) {
$error = true;
$nb = null;
$name = null;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
@ -5,14 +20,6 @@
<title>Hello World 3</title>
</head>
<body>
<?php
$nb = 0;
$name = "";
if (isset($_GET["nb"]) AND isset($_GET["name"])) {
$nb = (int)$_GET["nb"];
$name = htmlspecialchars($_GET["name"]);
}
?>
<form>
<label for="nb">Number: </label>
<input id="nb" type="number" name="nb" min="0" max="100" value="<?= $nb ?>" required>
@ -21,17 +28,17 @@
<input type="submit" value="Send">
</form>
<?php
if ($error) { ?>
<strong>Invalid args !</strong>
<?php } ?>
<ul>
<?php
if ($nb AND $name) {
if ($nb >= 0 and $nb <= 100)
for ($i = 0; $i < $nb; $i++) { ?>
<li>Hello <?= $name ?> !</li>
<?php }
else { ?>
<strong>Invalid args !</strong>
<?php if ($nb !== null AND $name !== null) {
for ($i = 0; $i < $nb; $i++) { ?>
<li>Hello <?= $name ?> !</li>
<?php }
} ?>
}?>
</ul>
</body>
</html>

View file

@ -1,3 +1,39 @@
<?php
$children = 0;
$married = false;
$income = 0;
if (isset($_POST["children"]) AND isset($_POST["income"])) {
$children = (int)$_POST["children"];
if (isset($_POST["married"]))
$married = (bool)$_POST["married"];
else
$married = false;
$income = (float)$_POST["income"];
}
if ($married)
$n = 2+$children/2;
else
$n = 1+$children/2;
$q = $income/$n;
$t = 0;
if ($q >= 0 AND $q <= 9963)
$t = $income*0 - 0*$n;
elseif ($q <= 27518)
$t = $income*0.14 - 1394.96*$n;
elseif ($q <= 73778)
$t = $income*0.3 - 5798*$n;
elseif ($q <= 156243)
$t = $income*0.41 - 13913.69*$n;
elseif ($q >= 156244)
$t = $income*0.45 - 20163.45*$n;
$t = round($t);
echo $q;
?>
<!DOCTYPE html>
<html lang="en">
<head>
@ -5,20 +41,7 @@
<title>Hello World 4</title>
</head>
<body>
<?php
$children = 0;
$married = false;
$income = 0;
if (isset($_GET["children"]) AND isset($_GET["income"])) {
$children = (int)$_GET["children"];
if (isset($_GET["married"]))
$married = (bool)$_GET["married"];
else
$married = false;
$income = (float)$_GET["income"];
}
?>
<form>
<form method="POST">
<label for="children">Number of children: </label>
<input id="children" type="number" name="children" min="0" value="<?= $children ?>" required> <br />
<label for="married">Married: </label>
@ -27,29 +50,7 @@
<input id="income" type="number" name="income" min="0" step="any" value="<?= $income ?>" required> <br />
<input type="submit" value="Send">
</form>
<?php
if ($married)
$n = 2+$children/2;
else
$n = 1+$children/2;
$q = $income/$n;
$t = 0;
if ($q >= 0 AND $q <= 9963)
$t = $income*0 - 0*$n;
elseif ($q >= 9964 AND $q <= 27518)
$t = $income*0.14 - 1394.96*$n;
elseif ($q >= 27519 AND $q <= 73778)
$t = $income*0.3 - 5798*$n;
elseif ($q >= 73779 AND $q <= 156243)
$t = $income*0.41 - 13913.69*$n;
elseif ($q >= 156244)
$t = $income*0.45 - 20163.45*$n;
$t = round($t);
?>
<p>Your taxes is <?= $t ?></p>
</body>
</html>