Hi everyone. I’m working on an assignment for class, and I can’t see
where my mistake is. I am asking the user for input (words), and while
the user input != " " it should ask for another word. Once the user
simply pushes “enter” without typing anything, it should quit, and show
the array order alphabetically. However, when I push enter without
typing anything, it asks me for another word, rather than ending.
I would really appreciate some help on this, as it is important for me
to understand WHY it isn’t working!
Here is my code so far:
words = []
puts “Please enter as many words as you would like, one line at a time.”
puts “To quit the program, simply push enter without typing any words.”
user_words = gets.chomp
while user_words != " " do
words.push user_words
puts “next word please”
user_words = gets.chomp
end
puts “Here are the words you entered sorted alphabetically:”
puts words.sort