【发布时间】:2014-02-19 03:27:40
【问题描述】:
我试图让用户输入一个数字,然后是第二个数字,它告诉程序做一些基本的数学运算多少次。我得到了工作和乘法的加法,但我不知道如何通过用户选择的次数让减法从自身减去一个数字。
print "Please Enter a numeric value: "; # get the first input from user
input1 = STDIN.gets.chomp!.to_i
puts ("\n" * 2) #Scroll the screen 3 times
print "Enter total number of times a value needs to be computed from #{input1} ";
input2 = STDIN.gets.chomp!.to_i
puts ("\n" * 2)
print "Addition : ", (input1.to_i * input2.to_i), "\n";
print "Subtraction : " , (input1.to_i - input2.to_i), "\n";
print "Multiplication : " , (input1.to_i ** input2.to_i), "\n";
【问题讨论】:
-
我误解了这个问题,所以删除了我的答案。我想你误解了
[v]*n,然而,v是第一个数字,n是第二个数字。这不是乘法。[2]*2 => [2,2],所以减法运算会产生2-2 => 0。
标签: ruby math subtraction