Cashpoint

Cashpoint

Vending notes to a customer.

A cashpoint can dispense £20, £10 and £5 notes. It always dispenses the least number of notes for each withdrawal. For example, if the customer chose to withdraw £50 it would dispense 2x£20 notes and 1x£10 note.


The dispenser mechanism is an embedded system that receives the commands, "Wx", "D20", "D10" or "D5" as an input sequence from the main control unit. For example, £50 would be W50 D20 D20 D10.

Make


Write a program to output the minimum number of notes from an input value.

Use this boilerplate code as a starting point:

Success Criteria

Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.

Complete the subprogram called `dispense` that:

  1. Outputs the amount the user is withdrawing in the format "Wx" where x is a number.
  2. Outputs "D20", "D10" or "D5" the correct number of times for the withdrawal.

Complete the `main program` so that:

  1. The user can input the amount they wish to withdraw as a whole number.

Typical inputs and outputs from the program would be:

Enter the amount to withdraw: £50

W50

D20

D20

D10


Enter the amount to withdraw: £75

W75

D20

D20

D20

D10

D5

Knowledge Organiser

Use these resources as a reference to help you meet the success criteria.

Programming guide:

Evaluate


Run the unit tests below to check that your program has met the success criteria.

Enter the amount to withdraw: £0

W0

Enter the amount to withdraw: £90

W90

D20

D20

D20

D20

D10

Enter the amount to withdraw: £200

W200

D20

D20

D20

D20

D20

D20

D20

D20

D20

D20

Enter the amount to withdraw: £315

W315

D20

D20

D20

D20

D20

D20

D20

D20

D20

D20

D20

D20

D20

D20

D20

D10

D5

Check that you have:

  • Used comments within the code to describe the purpose of subprograms, conditions and iterations.
  • Used meaningful identifier names. That means the names of subprograms and variables indicate what they are for.