Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pos(x, y)
- term.setCursorPos(x or 1, y or 1)
- end
- function c(x, y)
- term.clear()
- pos(x, y)
- end
- local side
- local sides = {"top", "bottom", "left", "right", "front", "back"}
- while true do
- local clear
- c()
- print("Printer is on which side?")
- local input = read()
- for i = 1, 6 do
- if sides[i] == input then
- clear = true
- end
- end
- if clear then
- side = input
- break
- end
- end
- local printer = peripheral.wrap(side)
- local name
- while true do
- local clear
- c()
- print("Who is this receipt for?")
- local input = read()
- name = input
- break
- end
- local items = {}
- local length = 5
- while true do
- c()
- print("Please enter item name")
- print("Try to make it as short as possible")
- print("Leave blank to print receipt")
- local input = read()
- if input:len() == 0 then
- break
- end
- if input:len() + 1 > length then
- length = input:len() + 1
- end
- c()
- while true do
- print("Price in credits? Must be a number.")
- print("Leave blank to cancel.")
- print("Set to 0 if it is free")
- local input2 = read()
- if input2 == "" then
- break
- end
- if tonumber(input2) then
- if input2 == "0" then
- input2 = "FREE"
- end
- items[#items+1] = {input, input2}
- break
- end
- end
- end
- local totalPrice = 0
- printer.newPage()
- printer.write("Item" .. string.rep(" ", length - 4) .. "Price")
- for i = 1, #items do
- local item = items[i][1]
- local price = items[i][2]
- printer.setCursorPos(1, i + 2)
- printer.write(item .. string.rep(" ", length - item:len()) .. price)
- if tonumber(price) then
- totalPrice = totalPrice + price
- end
- end
- printer.setCursorPos(1, #items + 4)
- printer.write("Total price: " .. totalPrice)
- printer.setPageTitle("Receipt: " .. name)
- printer.endPage()
- c()
- print("Page has been printed. The program will now exit.")
- sleep(2)
- c()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement