Php计算器与百分比计算

时间:2014-04-04 10:30:26

标签: php if-statement calculator

我需要一些帮助来制作一个PHP计算器!它是建筑机械租赁的计算器。因此,我将计算租用挖掘机“x”天的费用。第一天它将在此之后每天花费300和+ 200。但如果您租用超过7天,您将获得20%的折扣,如果您租用超过30天,您将获得50%的折扣!请帮帮我!

<form action="calc.php" method="get">
    <p>
        <label value="days">Antall dager: </label>
        <input class="field" type="number" min="1" max="50" name="days" value="1">
    </p>
    <p>
        <input id="button" type="submit" value="Regn ut!">
    </p>
</form>
<div style="text-align:center;">
<?php
    if (isset($_GET['days'])) {

    @$days = ($_GET['days']);

    $total = 300 + $days*200;
    echo "<br>";
    echo "Det vil koste ";
    echo "<span style='color:red;'>";
    echo $total, " KR ";
    echo "</span>";
    echo" å leie en byggtørker i ";
    echo $days;
    echo " dager.";
    }
?>
</div>

1 个答案:

答案 0 :(得分:-1)

如果你不能展示任何代码,我不会给你一个解决方案,但我可以给你一个推动:

首先,你做所有的计算。之后,您可以看到他们是否可以获得折扣:

var $total = 300;
$total+= 200* $numDays; // price per day

现在你想知道折扣,只需使用if / else / elseif:

if( $days > 30 ){ /* Do something with the price here, the 50% disacount */ ;}
elseif( $days > 20 ){ /* Do something with the price here, for upto 20days */ ;}
elseif( $days > 7 ){ /* Do something with the price here, 20% discounts */ ;}