我想用php计算电费
这是我的设想:我想用php计算电费,php,Php,这是我的设想: 如果单位为100&&200&&300,则每单位收费7卢比 if($units > 100){ $bill = 100 * 1; $remaining_units= $units -100; if($remaining_units > 100 ){ $remaining_units= $remaining_units -100; $bill = $bill + (100* 2); if($remaining_units > 100
- 如果单位为100&&200&&300,则每单位收费7卢比
if($units > 100){ $bill = 100 * 1; $remaining_units= $units -100; if($remaining_units > 100 ){ $remaining_units= $remaining_units -100; $bill = $bill + (100* 2); if($remaining_units > 100 || $remaining_units < 100){ $remaining_units= $remaining_units -100; $bill = $bill + (100* 3); if($remaining_units > 100 || $remaining_units < 100){ $bill = $bill + (100* 7); } } } } echo $bill;
if($units>100){ $bill=100*1; $剩余单位=$单位-100; 如果($剩余单位>100){ $剩余单位=$剩余单位-100; $bill=$bill+(100*2); 如果($resisting_units>100 | |$resisting_units<100){ $剩余单位=$剩余单位-100; $bill=$bill+(100*3); 如果($resisting_units>100 | |$resisting_units<100){ $bill=$bill+(100*7); } } } } echo美元钞票;
echo calculate_bill(210);
function calculate_bill($units, $multipler = 1, $oldBill=0){
if($units > 100){
$remainingUnits = $units -100;
$oldBill = (100 * $multipler) + $oldBill;
}else{
$a = ($units * $multipler) + ($oldBill);
return $a;
}
/*first level complete*/
if($multipler == 1){
$multipler = 2;
}elseif($multipler == 2){
$multipler = 3;
}elseif($multipler >= 3){
$multipler = 7;
}
return calculate_bill($remainingUnits,$multipler, $oldBill);
}
是的,现在工作很好
if($units < 100){
$bill = $units*1;
}elseif($units > 100 && $units <=200){
$temp = 100*1;
$remaining_units = $units - 100;
$bill = $temp + ($remaining_units *2);
}elseif($units > 200 && $units <=300){
$temp = (100*1)+ (100*2);
$remaining_units = $units - 200;
$bill = $temp + ($remaining_units *3);
}else{
$temp = (100*1)+ (100*2)+ (100*3);
$remaining_units = $units - 300;
$bill = $temp + ($remaining_units *7);
}
echo $bill;
if($units<100){
$bill=$units*1;
}埃尔塞夫($units>100&&$units 200&&$units你到目前为止尝试了什么,你到底想要什么?欢迎来到Stack。把你想要的代码放在你期望的地方,所以只给你代码?这就是软件开发人员的目的。雇一个。我投票结束这个问题,因为op只是问代码。对不起,我忘了把代码放在qu上估计