BobMe

BETTER money counter thing

Sep 17th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.60 KB | None | 0 0
  1. -- so javascript is really fucking gay so I'm forced to make this money counter thing on Lua.
  2. -- And if you're a fuckwit and want to argue saying I shouldn't of used JavaScript in the first place, how the hell did I know it's math was so
  3.  -- retarded?  I only used Javascript because it's faster with math.  Anyways, on to the script.
  4.  
  5. money = "$977.47"
  6.  
  7. ---don't change anything below here unless you're a nerd.
  8. number = tonumber(string.sub(money,2))
  9. hundred = 0
  10. fifty = 0
  11. twenty = 0
  12. ten = 0
  13. five = 0
  14. one = 0
  15.  
  16. quarter = 0
  17. dime = 0
  18. nickel = 0
  19. penny = 0
  20.  
  21. function deterdeci(x)
  22.     x = tostring(x)
  23.     local gar = false
  24.     for i=1,#x do
  25.         if string.sub(x,i,i) == "." and (string.sub(x,i+1,i+1) ~= "0" and string.sub(x,i+2,i+2) ~= "") then
  26.             gar = true
  27.             break
  28.         end
  29.     end
  30.     return gar
  31. end
  32.  
  33. function seperatedeci(x)
  34.     x = tostring(x)
  35.     for i=1,#x do
  36.         if string.sub(x,i,i) == "." then
  37.             local number = "0."..string.sub(x,i+1)
  38.             return tonumber(number)
  39.         end
  40.     end
  41. end
  42.  
  43. function removedeci(x)
  44.     x = tostring(x)
  45.     for i=1,#x do
  46.         if string.sub(x,i,i) == "." then
  47.             return tonumber(string.sub(x,1,i-1))
  48.         end
  49.     end
  50. end
  51.  
  52. --calculate coins
  53. if deterdeci(number) == true then
  54.     local num = seperatedeci(number)*100
  55.     while num ~= 0 do
  56.         if num % 25 == 0 then
  57.             quarter = quarter + 1
  58.             num = num - 25
  59.         elseif num % 10 == 0 then
  60.             dime = dime + 1
  61.             num = num - 10
  62.         elseif num % 5 == 0 then
  63.             nickel = nickel + 1
  64.             num = num - 5
  65.         else
  66.             penny = penny + 1
  67.             num = num - 1
  68.         end
  69.     end
  70.     number = removedeci(number)
  71. end
  72.  
  73. --calculate notes
  74. while number ~= 0 do
  75.     if number % 100 == 0 then
  76.         hundred = hundred + 1
  77.         number = number - 100
  78.     elseif number % 50 == 0 then
  79.         fifty = fifty + 1
  80.         number = number - 50
  81.     elseif number % 20 == 0 then
  82.         twenty = twenty + 1
  83.         number = number - 20
  84.     elseif number % 10 == 0 then
  85.         ten = ten + 1
  86.         number = number - 10
  87.     elseif number % 5 == 0 then
  88.         five = five + 1
  89.         number = number - 5
  90.     else
  91.         one = one + 1
  92.         number = number - 1
  93.     end
  94. end
  95.  
  96. print("The Amount, "..money..", requires:\n\n"..hundred.." $100 notes;\n"..fifty.." $50 notes; \n"..twenty.." $20 notes; \n"..ten.." $10 notes; \n"..five.." $5 notes; \n"..one.." $1 notes; \n"..quarter.." quarters; \n"..dime.." dimes; \n"..nickel.." nickels; \nand "..penny.." pennies.")
Add Comment
Please, Sign In to add comment