This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

changeGetter

By: a guest on Mar 11th, 2013  |  syntax: Lua  |  size: 0.85 KB  |  views: 43  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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?" )
  34. userInput = io.read()
  35. getChange( userInput )
clone this paste RAW Paste Data