我想在不同的方法中添加从用户输入声明的变量的值,以便如何对来自不同方法的所有变量值求和,sum=a+c+d
并根据总和声明一些语句。
class Mets
attr_accessor :wp
attr_accessor :hdl
attr_accessor :tc
def initialize(wp,hdl,tc)
@wp = wp`enter code `
@hdl = hdl
@tc = tc
end
`
#type the wp number within the ranges and enter it will return "a" value pertaining to that range
print"what is the wp?"
wp=gets.to_i
case wp
when 95..100 then print "a=1\n"
when 101..102 then print "a=2\n"
when 103..110 then print "a=3\n"
when 111..120 then print "a=4\n"
when 121..130 then print "a=5\n"
end
#type the hdl number within the ranges and enter it will return "a" value pertaining to that range
print"what is the hdl?"
hdl=gets.to_i
case hdl
when 40..49 then print "c=1\n"
when 10..39 then print "c=3\n"
end
#type the tc number within the ranges and enter it will return "a" value pertaining to that range
print "what is the tc?"
tc=gets.to_i
case tc
when 160..199 then print "d=2\n"
when 200..239 then print "d=4\n"
when 240..279 then print "d=5\n"
when 280..500 then print "d=6\n"
end
end
#output: you see values of a,c,d printing pertaining to that ranges,now i want to add all this variables(a,c,d) declared after user inputs ?please suggest what has to be done