Калькулятор на руби. (Стеки, бинарные-унарные вычисления и другие извращения)
есть код
num1 = num1.to_i
num2 = num1.to_i
def Add(num1, num2)
res = num1+num2
puts res
end
def Minus(num1, num2)
res = num1-num2
puts res
end
def Multiply(num1, num2)
res = num1*num2
puts res
end
def Division(num1, num2)
res = num1/num2
puts res
end
puts = 'Calculator has started'
# Ячейка памяти
memory = 0
while true
puts "Calculator has started"
print 'Type number: '
result = gets.strip.to_i
while true
print 'Type operation: '
operation = gets.strip
break if operation == ""
if operation == 'mw'
memory = result
elsif operation == 'mr'
result = memory
else
print 'Type number: '
second_number = gets.strip.to_i
end
if operation == "+"
result += second_number
elsif operation == "-"
result -= second_number
elsif operation == "*"
result *= second_number
elsif operation == "/"
begin
result /= second_number
rescue ZeroDivisionError
puts 'Zero divizion error'
result /= 1
end
end
print 'Result: '
puts result
end
end
мне нужно что б он мог работать со стеками, работать в бинарные/унарные операции: +, *, -, /, mod, --, sqrt, sin, cos, tan, ctan, exp, ln, !,
и рассчитывать простые числа, ну и валидация данных...