Advertisement
LoganDark

Receipt System

Dec 23rd, 2015
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.82 KB | None | 0 0
  1. function pos(x, y)
  2.  term.setCursorPos(x or 1, y or 1)
  3. end
  4.  
  5. function c(x, y)
  6.  term.clear()
  7.  pos(x, y)
  8. end
  9.  
  10. local side
  11. local sides = {"top", "bottom", "left", "right", "front", "back"}
  12.  
  13. while true do
  14.  local clear
  15.  c()
  16.  print("Printer is on which side?")
  17.  local input = read()
  18.  for i = 1, 6 do
  19.   if sides[i] == input then
  20.    clear = true
  21.   end
  22.  end
  23.  if clear then
  24.   side = input
  25.   break
  26.  end
  27. end
  28.  
  29. local printer = peripheral.wrap(side)
  30. local name
  31.  
  32. while true do
  33.  local clear
  34.  c()
  35.  print("Who is this receipt for?")
  36.  local input = read()
  37.  name = input
  38.  break
  39. end
  40.  
  41. local items = {}
  42. local length = 5
  43.  
  44. while true do
  45.  c()
  46.  print("Please enter item name")
  47.  print("Try to make it as short as possible")
  48.  print("Leave blank to print receipt")
  49.  local input = read()
  50.  if input:len() == 0 then
  51.   break
  52.  end
  53.  if input:len() + 1 > length then
  54.   length = input:len() + 1
  55.  end
  56.  c()
  57.  while true do
  58.   print("Price in credits? Must be a number.")
  59.   print("Leave blank to cancel.")
  60.   print("Set to 0 if it is free")
  61.   local input2 = read()
  62.   if input2 == "" then
  63.    break
  64.   end
  65.   if tonumber(input2) then
  66.    if input2 == "0" then
  67.     input2 = "FREE"
  68.    end
  69.    items[#items+1] = {input, input2}
  70.    break
  71.   end
  72.  end
  73. end
  74.  
  75. local totalPrice = 0
  76.  
  77. printer.newPage()
  78. printer.write("Item" .. string.rep(" ", length - 4) .. "Price")
  79.  
  80. for i = 1, #items do
  81.  local item = items[i][1]
  82.  local price = items[i][2]
  83.  printer.setCursorPos(1, i + 2)
  84.  printer.write(item .. string.rep(" ", length - item:len()) .. price)
  85.  if tonumber(price) then
  86.   totalPrice = totalPrice + price
  87.  end
  88. end
  89.  
  90. printer.setCursorPos(1, #items + 4)
  91. printer.write("Total price: " .. totalPrice)
  92.  
  93. printer.setPageTitle("Receipt: " .. name)
  94. printer.endPage()
  95. c()
  96. print("Page has been printed. The program will now exit.")
  97. sleep(2)
  98. c()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement