#!/usr/bin/lua
-- change.lua -- works out the change for a given amount
-- Made by Joseph Salisbury -- 24/01/09
totalValue = tonumber( (arg[1]) ) -- The value to reach
-- The available denominations
coins = {200, 100, 50, 20, 10, 5, 2, 1}
coinNames = {
[200] = "2 pound piece",
[100] = "1 pound piece",
[50] = "50 pence piece",
[20] = "20 pence piece",
[10] = "10 pence piece",
[5] = "5 pence piece",
[2] = "2 pence piece",
[1] = "1 pence piece",
}
function usage()
usage = "Usage: change.lua [amount]"
return usage
end
if totalValue then
while totalValue ~= 0 do
for i=1, #coins do
while totalValue >= coins[i] do
print( coinNames[coins[i]] )
totalValue = totalValue - coins[i]
end
end
end
else
print( usage() )
end