Bolodefchoco_LUAXML

[Learning] Calculadora Simples

Dec 25th, 2016
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.93 KB | None | 0 0
  1. getNumbers = function(operation)
  2.     os.execute("cls")
  3.     local n = {}
  4.     for k,v in next,{"primeiro","segundo"} do
  5.         io.write("Digite o "..v.." numero para a "..operation..": ")
  6.         n[#n+1] = io.read()
  7.     end
  8.     return n
  9. end
  10.  
  11. menu = function()
  12.     os.execute("cls")
  13.     local choice
  14.     local operations = {{"adicao",'+'},{"subtracao",'-'},{"multiplicacao",'*'},{"divisao",'/'},{"exponenciacao",'^'}}
  15.     io.write("Informe o numero correspondente a uma das operacoes abaixo:\n")
  16.     for k,v in next,operations do
  17.         io.write(string.format("\t%d -> Operacao aritmetica de %s (X%sY)\n",k,v[1],v[2]))
  18.     end
  19.     io.write("\n> ")
  20.     choice = io.read()
  21.     choice = tonumber(choice)
  22.     local numbers = getNumbers(operations[choice][1])
  23.     os.execute("cls")
  24.     io.write("A "..operations[choice][1].." entre "..numbers[1].." e "..numbers[2].." é: "..tostring(load("return "..numbers[1]..operations[choice][2]..numbers[2])()))
  25.     os.execute("pause >nul")
  26.     menu()
  27. end
  28.  
  29. menu()
Add Comment
Please, Sign In to add comment