Someone has 100,000 yuan and needs to pay a toll every time he crosses the intersection. The rules are:
1. When the cash is > 50,000, pay 5% each time
2. When the cash is < 50,000 When paying 5000 each time
Answer: Calculate how many intersections the person can pass
听装雪碧2017-08-09 11:39:33
$money = 100000; $count = 0; for ($count=0; $money > 5000 ; $count++) { if ($money > 50000) { $money = $money * 0.95; } else if($money <= 50000) { $money -= 5000; } echo '当第'.($count+1).'次经过这个路口时,剩余金钱'.$money.'<br>'; } echo '<hr>'; echo '一共可以经过'.$count.'次';
辕天2017-08-08 17:26:51
$money = 100000; $num = 0; do { $money = $money - $money * 0.05; $num++; } while ($money > 50000); while ($money >= 5000) { $money = $money - 5000; $num++; } echo 'Num: ' . $num;
By the way, where are the rules and fees so high?
ringa_lee2017-08-08 14:13:18
First draw a rough outline, and then slowly write the logic, it will not be difficult to understand
ringa_lee2017-08-08 14:10:49
$money = 100000;
$num = 1;
if($money > 50000){
//Pay 5%
}else{
//Pay 5000
}