• API
• FAQ
• Tools
• Trends
• Archive
daily pastebin goal
60%
SHARE
TWEET

# changeGetter

a guest Mar 11th, 2013 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. --Change calculator
2. function getChange( money )
3.         --Convert from dollars and cents to just cents
4.         money = math.floor( ( money * 100 ) )
5.         --Process
6.         print( "Your change - " )
7.
8.         quarters = math.floor( ( money / 25 ) )
9.         if( quarters > 0 ) then
10.                 money = money - ( quarters * 25 )
11.                 print( "Quarters: " .. tostring( quarters ) )
12.         end
13.
14.         dimes = math.floor( ( money / 10 ) )
15.         if( dimes > 0 ) then
16.                 money = money - ( dimes * 10 )
17.                 print( "Dimes: " .. tostring( dimes ) )
18.         end
19.
20.         nickels = math.floor( ( money / 5 ) )
21.         if( nickels > 0 ) then
22.                 money = money - ( nickels * 5 )
23.                 print( "Nickels: " .. tostring( nickels ) )
24.         end
25.
26.         pennies = ( money / 1 )
27.         if( pennies > 0 ) then
28.                 money = money - pennies
29.                 print( "Pennies: " .. tostring( pennies ) )
30.         end
31. end
32.
33. print( "How much money do you have?" )