@Aniri14

Как добавить поддержку унарных операций в ruby калькулятор?

есть калькулятор:
--, sqrt, sin, cos, tan, ctan, exp, ln, !
, что бы считало? по запросу sin выводил синус, и тд. Мне хотя бы просто пример, с остальным я разберусь. Спасибо огромное заранее.

как добавить в нём поддержку
# цепной калькулятор

  while true do
  puts "Calculator has started"
  
  print 'Type number: '
  result = gets.strip.to_i
  print 'Type operation: '
  operation = gets.strip

  while true do
    print 'Type number: '
    second_number = gets.strip.to_i
    if operation == "+"
      result += second_number
    elsif operation == "-"
      result -= second_number
    elsif operation == "*"
      result *= second_number
    elsif operation == "/"
      result /= second_number
      elsif operation == "**"
      result **= second_number
          elsif operation == "%"
      result %= second_number
      
        end
 
    print 'Result: '
    puts result
 
    operation = gets.strip
    break if operation == ""
  end
end

# Ячейка пам¤ти, не сбрасывается при рестарте калькул¤тора
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 == "/"
      result /= second_number
      elsif operation == "**"
      result **= second_number
    
      end
    end
    print 'Result: '
    puts result
  end
  • Вопрос задан
  • 212 просмотров
Решения вопроса 1
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы