Isaac T. wrote:
Ok now im trying to ask for 5 words ON THE SAME LINE then it prints the
first word also once i get this to work then im going to make it where
it has 2 variables. one is the array and it’s adding 1 so the value of
the array is diff. then ill use that same array as a text variable to
show which array your on.
First this is my code with help from the first reply
puts “Ok now enter in words just be sure there are spaces inbetween
them”
word_group = []
words_group = gets.chomp.split(" " + " ")
word_group<< words_group
print “The first word you entered was: #{word_group[0]}”
this is my goal of a running program:
|
|Ok now enter in 5 words just be sure there are spaces inbetween them: Jo, Mo, Lo, Ho, No
|The first word you entered was Jo followed by Mo
|____________________________________________________________________
puts ‘Please enter 5 words on the same line with spaces then press
enter:’
input = gets.chomp.split
print ‘The first word you entered was ’
puts input.join(’ followed by ')
–output:–
Please enter 5 words on the same line with spaces then press enter:
jack diane larry mo curly
The first word you entered was jack followed by diane followed by larry
followed by mo followed by curly
|
|Ok now enter in 5 words just be sure there are spaces inbetween them: Jo, Mo, Lo, Ho, No
|The first word you entered was Jo
|The second word you entered was Mo
|The third word you entered was Lo
|The fourth word you entered was Ho
|The fifth word you entered was No
|_______________________________________________________________________________________________
yeah i understand that it might be hard to understand what im asking so
if more explaining is needed i will
You don’t write well enough yet to convey ideas in words. You
especially have to be a good writer when asking about computer
programming problems because the details are very important.
places = [‘first’, ‘second’, ‘third’, ‘fourth’, ‘fifth’]
puts ‘Please enter 5 words on the same line with spaces then press
enter:’
input_words = gets.chomp.split
input_words.each_with_index do |word, i|
puts “The %s word you entered was %s” % [places[i], word]
end
–output:–
Please enter 5 words on the same line with spaces then press enter:
jack diane larry mo curly
The first word you entered was jack
The second word you entered was diane
The third word you entered was larry
The fourth word you entered was mo
The fifth word you entered was curly