我的红宝石计算器不会输出到我的控制台

问题描述

所以我正在使用原子来编写计算器,但似乎无法获得控制台来输出看跌期权的第一个实例。它只是说[在2.88秒内完成]。是否有任何遗漏导致我的代码无法打印到控制台,或者我只是愚蠢地认为应该向控制台输出任何内容?这是我的代码:


def add
  puts "What is the first number to be added?"
  n1 = gets.chomp
  puts "What is the second number to be added?"
  n2 = gets.chomp
  answer = n1 + n2
  puts "Congrats,your number is #{answer}"
end
def sub
  puts "What is the first number to be subtracted?"
  n1 = gets.chomp
  puts "What is the second number to be subtracted?"
  n2 = gets.chomp
  answer = n1 - n2
  puts "Congrats,your number is #{answer}"
end
def multiply
  puts "What is the first number to be multiplied?"
  n1 = gets.chomp
  puts "What is the second number to be multiplied?"
  n2 = gets.chomp
  answer = n1 * n2
  puts "Congrats,your number is #{answer}"
end
def divide
  puts "What is the first number to be divided?"
  n1 = gets.chomp
  puts "What is the second number to be divided?"
  n2 = gets.chomp
  answer = n1 / n2
  puts "Congrats,your number is #{answer}"
end

print "Would you like to add,subtract,multiply,or divide a number? "
response = gets.chomp
if response == "add" then
  add
elsif response == "subtract" then
  sub
elsif response == "multiply" then
  multiply
else response == "divide"
  divide
end

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...