Advertisement
Skiprune

Untitled

Jul 10th, 2020
1,278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.85 KB | None | 0 0
  1. local monitor = peripheral.wrap("right")
  2.  
  3. function newLine()
  4.   x,y = monitor.getCursorPos()
  5.   monitor.setCursorPos(1,y+1)
  6. end
  7.  
  8. function add(x, y)
  9.   monitor.write(x+y)
  10.   newLine()
  11. end
  12.  
  13. function subtract(x, y)
  14.   monitor.write(x-y)
  15.   newLine()
  16. end
  17.  
  18. function multiply(x, y)
  19.   monitor.write(x*y)
  20.   newLine()
  21. end
  22.  
  23. function divide(x, y)
  24.   monitor.write(x/y)
  25.   newLine()
  26. end
  27. while(true) do
  28.   monitor.clear()
  29.   monitor.setCursorPos(1,1)
  30.   monitor.setTextColor(1024)
  31.   io.write("Enter first number")
  32.   x = io.read(
  33.   io.write("Enter second number")
  34.   y = io.read
  35.   io.write("Enter operation")
  36.   op = io.read
  37.    
  38.   if op == "add" then
  39.     add(x,y)
  40.   end
  41.    
  42.   if op == "subtract" then
  43.     subtract(x,y)
  44.   end
  45.    
  46.   if op == "multiply" then
  47.     multiply(x,y)
  48.   end
  49.    
  50.   if op == "divide" then
  51.     divide(x,y)
  52.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement