I am trying to subtract two values in my array the largest and the smallest. I have sorted them then tried to subtract them but the output is different. I am also trying to use a loop but I keep getting errors. It would be nice to show me what I am doing wrong. thanks
numbers = [randomNo = rand(50),randomNo = rand(50),randomNo = rand(50),randomNo = rand(50)]
loop do
puts "type s to start and q to quit"
input = STDIN.gets
break if input == q
puts numbers.sort.inspect
puts numbers.first - numbers.last
end
output:[3, 13, 21, 46]
18
I wanted 46 – 3
What about this instead?