Advertisement
Guest User

02. Shopping PHP

a guest
Mar 13th, 2018
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. <?php
  2. $budget = floatval(readline());
  3. $numOfChocolate = intval(readline());
  4. $quantityMilk = floatval(readline());
  5.  
  6. $mandarin = 0.20;
  7. $chocolate = 0.65;
  8. $literMilk = 2.70;
  9. //$quantityMandarin = $numOfChocolate - $numOfChocolate * 0.35;
  10.  
  11. $totalPriceChocolate = $numOfChocolate * $chocolate;
  12. $totalPriceMilk = $quantityMilk * $literMilk;
  13. $totalPriceMandarin = floor($numOfChocolate - ($numOfChocolate * 0.35)) * $mandarin;
  14.  
  15. $total = $totalPriceChocolate + $totalPriceMilk + $totalPriceMandarin;
  16.  
  17. $leftMoney = abs($budget-$total);
  18.  
  19. if($total <= $budget){
  20.     printf("You got this, %.2f money left!",$leftMoney) ;
  21. }else{
  22.     printf("Not enough money, you need %.2f more!",$leftMoney) ;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement