0

如果有人要制造一台“自动售货机”,你会写下你要付多少钱,如果你为一件 2 英镑的商品支付了 100 英镑,那么让它与你得到的金额相呼应,然后以硬币的形式相呼应( 1p,5p 等。如果你明白我的意思。)你会如何做硬币的回声?

$valg = $_POST['select'];
$pris = $_POST['pris'];

$r_pris = explode(" ", $valg);
$resultat = $r_pris['1']-$pris; 

if ($resultat<0){
    $slut_pris = "du skal have " . $resultat . " kroner tilbage";
} elseif($resultat==0){
    $slut_pris = "lige og plet på.";
}
else {
    $slut_pris = "du mangler " . $resultat . " kroner";
}
4

1 回答 1

1

你可以这样做

<?php

$amt_paid = 100; //Fetch the user input
$real_amount = 2; //Pre-Defined Amount

if($amt_paid > $real_amount) { //Check whether the paid amount is more than defined amount
    $amount_paybck = $amt_paid - $real_amount;
    echo '£'.$amount_paybck; //You can divide this value to get a output in coins
    echo '10P'.ceil($amount_paybck/10).'<br />'; //Coins of 10
    echo '5P'.ceil($amount_paybck/5).'<br />'; //Coins of 5
    echo '2P'.ceil($amount_paybck/2).'<br />'; //Coins of 2
} else {
    echo 'Amount paid is in-sufficient';
}

?>
于 2013-02-28T13:43:06.430 回答