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.
Write a program to output the minimum number of notes from an input value.
Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.
dispense that:Enter the amount to withdraw: £
50
W50
D20
D20
D10
Enter the amount to withdraw: £
75
W75
D20
D20
D20
D10
D5
// Cashpoint program
using System;
class Submission
{
---
// -------------------------
// Subprograms
// -------------------------
// Control unit output
---
static void dispense(string amount)
{
---
Console.WriteLine("W" + amount);
// £20 notes
int iamount = Convert.ToInt32(amount);
while (iamount >= 20)
{
---
Console.WriteLine("D20");
iamount = iamount - 20;
---
}
---
// £10 notes
while (iamount >= 10)
{
---
Console.WriteLine("D10");
iamount = iamount - 10;
---
}
---
// £5 notes
while (iamount >= 5)
{
---
Console.WriteLine("D5");
iamount = iamount - 5;
---
}
---
}
---
// -------------------------
// Main program
// -------------------------
public static void Main(string[] args)
{
---
Console.WriteLine("Enter the amount to withdraw: £");
string amount = Console.ReadLine();
---
dispense(amount);
---
}
---
}