如何解决我的红宝石计算器不会输出到我的控制台
所以我正在使用原子来编写计算器,但似乎无法获得控制台来输出看跌期权的第一个实例。它只是说[在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 举报,一经查实,本站将立刻删除。