Hi, I have been trying to turn stuff like 30 into three 10s or 45 into four 10s and one 5.
I have tried with the code below which doing numbers like 30 work, but numbers like 15 only print the 10 out.
function turnNumberToMoney(n) if n < 10 then return n end local nums = {} repeat wait() if n ~= 10 then if n > 10 then table.insert(nums,10) n = n - 10 else table.insert(nums,n) break end else if n == 10 then table.insert(nums,10) end if n == 5 then table.insert(nums,5) end break end until n < 10 return nums end local num = turnNumberToMoney(15) for i,v in pairs(num) do print(v) end
I got it working for numbers under 1000
function convert10(num) local str = tostring(num) local n1,n2 = str:sub(1,1),str:sub(2,2) local tab = {} for i = 1,tonumber(n1) do table.insert(tab,10) end table.insert(tab,n2) return tab end function convert100(str) local num = tostring(str) local n1,n2,n3 = num:sub(1,1),num:sub(2,2),num:sub(3,3) local tab = {} for i = 1,tonumber(n1.."0") do table.insert(tab,10) end for i = 1,tonumber(n2) do table.insert(tab,10) end table.insert(tab,n3) return tab end