Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local nprompt = function(q)
- print(q)
- term.blit("> ","3 "," ")
- return tonumber(read())
- end
- local round = function(num)
- return math.floor((num*100)+0.5)/100
- end
- term.clear()
- term.setCursorPos(1,1)
- local amntOfMonths = 12 --nprompt("Length of loan? (months)")
- local monthlyPayment = nprompt("Monthly payment?")
- local principle = nprompt("Principle?")
- local interestRate = nprompt("Interest rate?")/100
- local payoffMonths = nprompt("Payoff after how long? (months)")
- local totalMonths = nprompt("Total months of loan?")
- local getIt = function(payoffMonths)
- output = {{}}
- output[1].interest = principle * interestRate * (1/amntOfMonths)
- output[1].principle = monthlyPayment - output[1].interest
- output[1].newPrinciple = principle - output[1].principle
- for a = 2, payoffMonths do
- output[a] = {}
- output[a].interest = output[a-1].newPrinciple * interestRate * (1/amntOfMonths)
- output[a].principle = monthlyPayment - output[a].interest
- output[a].newPrinciple = output[a-1].newPrinciple - output[a].principle
- end
- output[#output].principle = output[#output-1].newPrinciple
- output[#output].newPrinciple = 0
- finalPayment = output[#output].interest + output[#output].principle
- return output,finalPayment
- end
- local printOutput = function(output,finalPayment)
- local max = {}
- for a = 1, #output do
- max.interest = math.max(#tostring(output[a].interest), max.interest or 0)
- max.principle = math.max(#tostring(output[a].principle), max.principle or 0)
- max.newPrinciple = math.max(#tostring(output[a].newPrinciple), max.newPrinciple or 0)
- end
- for k,v in pairs(max) do
- max[k]=v+1
- end
- term.setCursorPos(1,1)
- term.write("Int.")
- term.setCursorPos(max.interest+1,1)
- term.write("Pri.")
- term.setCursorPos(max.interest+max.principle+1,1)
- term.write("NewPri.")
- for a = 1, #output do
- term.setCursorPos(1,a+1)
- term.write(round(output[a].interest))
- term.setCursorPos(max.interest+1,a+1)
- term.write(round(output[a].principle))
- term.setCursorPos(max.interest+max.principle+1,a+1)
- term.write(round(output[a].newPrinciple))
- end
- term.setCursorPos(1,#output+3)
- print("Final payment: "..tostring(round(finalPayment)))
- end
- local tab1, finalPay1 = getIt(payoffMonths)
- local tab2, finalPay2 = getIt(totalMonths)
- term.clear()
- printOutput(tab1,finalPay1)
- print("You saved: "..round(finalPay1-finalPay2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement