Here's the question you clicked on:
tapfu
Write a program to simulate a vending machine and calculate change based on the amount paid. Given the cost, the user should first be prompted to add more money until the cost is met/exceeded by the payment. Assume that all change is given in coins only and coins come in the following denominations: R5, R2, R1, 50c, 20c, 10c, 5c
This is a classic State Machine problem. Use the total deposited as the state. Use transition events like vend, addcoin and cancel. Many State Machine examples can be found online a good example for this problem is here: http://www.gamedev.net/blog/802/entry-2217738-system-design----finite-state-machines/