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.
01 | function turnNumberToMoney(n) |
02 | if n < 10 then |
03 | return n |
04 | end |
05 | local nums = { } |
06 | repeat wait() |
07 | if n ~ = 10 then |
08 | if n > 10 then |
09 | table.insert(nums, 10 ) |
10 | n = n - 10 |
11 | else |
12 | table.insert(nums,n) |
13 | break |
14 | end |
15 | else |
I got it working for numbers under 1000
01 | function convert 10 (num) |
02 | local str = tostring (num) |
03 | local n 1 ,n 2 = str:sub( 1 , 1 ),str:sub( 2 , 2 ) |
04 | local tab = { } |
05 |
06 | for i = 1 , tonumber (n 1 ) do |
07 | table.insert(tab, 10 ) |
08 | end |
09 | table.insert(tab,n 2 ) |
10 | return tab |
11 | end |
12 |
13 | function convert 100 (str) |
14 | local num = tostring (str) |
15 | local n 1 ,n 2 ,n 3 = num:sub( 1 , 1 ),num:sub( 2 , 2 ),num:sub( 3 , 3 ) |