Logic problem, I can't wrap my head around it
HUNT
HUNT 2017-08-08 12:53:03
0
4
1213

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

HUNT
HUNT

reply all (4)
听装雪碧
$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.'
'; } echo '
'; echo '一共可以经过'.$count.'次';


    辕天
    $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?

    • reply My gate fee rules
      HUNT author 2017-08-08 20:02:46
    ringa_lee

    First draw a rough outline, and then slowly write the logic, it will not be difficult to understand

      ringa_lee

      $money = 100000;

      $num = 1;

      if($money > 50000){

      //Pay 5%

      }else{

      //Pay 5000

      }

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!