Paying at the Machine
The last step: paying. The new variable paid says how much money the driver put into the machine: a 20 EUR note. The machine prints how much was paid and gives back the change. It has 5 EUR notes, 2 EUR coins and 1 EUR coins, and it gives back as few pieces as possible: as many notes as fit, then 2 EUR coins, and the rest in 1 EUR coins. For our car, the output ends like this:
Fee: 6 EUR
Paid: 20 EUR
Change: 14 EUR
5 EUR notes: 2
2 EUR coins: 2
1 EUR coins: 0When the money isn't enough, the machine gives nothing back and prints how much is missing: Not enough: 1 EUR missing when the driver puts in only 5 EUR. And when the parking is free, the machine gives all the money back.
A tip: how many 5 EUR notes fit into the change, and how much is left over after them? You've answered questions like that with / and % before.
That's the whole project. With just three lessons behind you, you've written the program of a real pay machine: it calculates with whole numbers, makes decisions with conditions and prints a clear receipt. In the next lesson, on loops, you'll learn to make a program repeat statements, so that it could, for example, work out the fees of all the cars that leave the garage in a day.
Instructions
Print how much was paid and the change. When the money isn't enough, print how much is missing instead.
Below the change, print how many notes and coins of each kind the machine gives back.
Start programming for free
3/3