Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- checkoutcomputer = 32
- alogin = "adminpassword"
- function connect()
- rednet.open("bottom")
- end
- success = pcall(connect)
- if not success then
- os.reboot()
- end
- monitor = peripheral.wrap("top")
- if not monitor then
- os.reboot()
- end
- function displayBalance(balance)
- monitor.clear()
- monitor.setCursorPos(1, 2)
- monitor.write("Welcome!")
- monitor.setCursorPos(1, 4)
- monitor.write("$" .. balance)
- end
- function checkOut(balance)
- success = false
- while success ~= "true" do
- rednet.send(checkoutcomputer, balance)
- id, success = rednet.receive()
- end
- print("SUCCESS!")
- end
- function evaluateFormula(formula)
- -- Load the formula as a Lua function
- local func, err = load("return " .. formula)
- -- Check if there was an error compiling the formula
- if not func then
- return nil, "Invalid formula: " .. err
- end
- -- Execute the function and return the result
- local success, result = pcall(func)
- if success then
- return result
- else
- return nil, "Error evaluating formula: " .. result
- end
- end
- balance = 0
- displayBalance(balance)
- while true do
- print("type end to confirm order \n")
- print("Current Order: $" .. balance)
- input = io.read()
- if input == alogin then
- os.exit(1)
- end
- if input == "end" then
- checkOut(balance)
- break
- end
- if input ~= 0 then
- change = evaluateFormula(input)
- if change then
- balance = balance + change
- end
- displayBalance(balance)
- end
- end
- monitor.clear()
- monitor.setCursorPos(1, 2)
- monitor.write("Thank")
- monitor.setCursorPos(1, 4)
- monitor.write("You!")
- os.sleep(5)
- displayBalance(0)
Advertisement
Add Comment
Please, Sign In to add comment