title: Getting nil error when adding elements in Array - Ruby
body: <p>I am trying to get a number from the user, store this number in the array and then add everything in the array together to display a total.</p>
  <pre><code>names = Array.new(20)
  sum = 0
  
  x = 0
  
  for index in 0..5
    puts &quot;Enter a number: &quot;
    data = gets.to_i
    names.push data
    x = x + names[index]
  end
  
  puts x
  </code></pre>
  <p>But I am getting the error <code>rb:10:in `+': nil can't be coerced into Integer (TypeError)</code></p>
  <p>I guess its not allowing me to add whatever is in the array together. Anybody know a workaround for this?</p>