Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- so javascript is really fucking gay so I'm forced to make this money counter thing on Lua.
- -- 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
- -- retarded? I only used Javascript because it's faster with math. Anyways, on to the script.
- money = "$977.47"
- ---don't change anything below here unless you're a nerd.
- number = tonumber(string.sub(money,2))
- hundred = 0
- fifty = 0
- twenty = 0
- ten = 0
- five = 0
- one = 0
- quarter = 0
- dime = 0
- nickel = 0
- penny = 0
- function deterdeci(x)
- x = tostring(x)
- local gar = false
- for i=1,#x do
- if string.sub(x,i,i) == "." and (string.sub(x,i+1,i+1) ~= "0" and string.sub(x,i+2,i+2) ~= "") then
- gar = true
- break
- end
- end
- return gar
- end
- function seperatedeci(x)
- x = tostring(x)
- for i=1,#x do
- if string.sub(x,i,i) == "." then
- local number = "0."..string.sub(x,i+1)
- return tonumber(number)
- end
- end
- end
- function removedeci(x)
- x = tostring(x)
- for i=1,#x do
- if string.sub(x,i,i) == "." then
- return tonumber(string.sub(x,1,i-1))
- end
- end
- end
- --calculate coins
- if deterdeci(number) == true then
- local num = seperatedeci(number)*100
- while num ~= 0 do
- if num % 25 == 0 then
- quarter = quarter + 1
- num = num - 25
- elseif num % 10 == 0 then
- dime = dime + 1
- num = num - 10
- elseif num % 5 == 0 then
- nickel = nickel + 1
- num = num - 5
- else
- penny = penny + 1
- num = num - 1
- end
- end
- number = removedeci(number)
- end
- --calculate notes
- while number ~= 0 do
- if number % 100 == 0 then
- hundred = hundred + 1
- number = number - 100
- elseif number % 50 == 0 then
- fifty = fifty + 1
- number = number - 50
- elseif number % 20 == 0 then
- twenty = twenty + 1
- number = number - 20
- elseif number % 10 == 0 then
- ten = ten + 1
- number = number - 10
- elseif number % 5 == 0 then
- five = five + 1
- number = number - 5
- else
- one = one + 1
- number = number - 1
- end
- end
- 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