我对PHP的了解尚未达到一定程度,每购买10张门票,门票就会回收2欧元折扣。我只能用10欧元来折扣2欧元,但我怎么能这样做呢?每10张票就提高2欧元?
<h1>Aantal gekochte tickets</h1>
<br><br>
<form method="POST">
Aantal tickets: <input name="tickets"></input><br><br>
<input type="submit" name="submit"></input>
</form>
<?php
if(isset($_POST['tickets'])) {
$tickets = $_POST['tickets'];
echo "<br><br>1 Ticket kost 2 euro<br><br>";
$sum = $tickets * 2;
if ($tickets % 10 == 0) {
$sum = $tickets *2 - 2;
echo "Je betaald 2 euro minder bij de 10e ticket<br><br>";
}
echo "Totaal kosten de tickets: " . $sum . "euro";
}
?>
答案 0 :(得分:0)
答案 1 :(得分:0)
<h1>Aantal gekochte tickets</h1>
<br><br>
<form method="POST">
Aantal tickets: <input name="tickets"></input><br><br>
<input type="submit" name="submit"></input>
</form>
<?php
if(isset($_POST['tickets'])) {
$tickets = $_POST['tickets'];
echo "<br><br>1 Ticket kost 2 euro<br><br>";
$sum = $tickets * 2;
// if tickets more than 10, it go into condition
if ($tickets >= 10) {
$discount=$tickets/10; // discount for each 10 tickets
$sum = $tickets *2 - (floor($discount)*2);
echo "Je betaald 2 euro minder bij de 10e ticket<br><br>";
}
echo "Totaal kosten de tickets: " . $sum . "euro";
}
?>