Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $budget = intval(readline());
- while (true){
- $itemSum = 0;
- $item = readline();
- if($item == "Stop"){
- break;
- }
- for ($i = 0; $i < strlen($item); $i++){
- $itemSum += intval($item[$i]);
- }
- $budget = $budget - $itemSum;
- if($budget < 0){
- echo "Not enough money!";
- return;
- } else{
- echo "Item successfully purchased!";
- }
- }
- echo "Money left: $budget";
Add Comment
Please, Sign In to add comment