From: darren kirby Date: 2008-02-18T10:59:12+09:00 Subject: Re: displaying user inputed arrays quoth the Isaac Toothyxdip: > 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 This is really redundant. First you create an empty array. Then you input your words to a different array, then you append your word array onto the end of the empty array. And this: > " " + " " just concatenates two spaces resulting in the call to 'split' being: > words_group = gets.chomp.split(" ") # two spaces Which won't split your input with 1 space between each word at all. The default argument to 'split' is a single space, so try this: > word_group = gets.chomp.split which will replace your three lines above. Use irb to explore and play with all these code snippets to get instant feedback on what things do! > 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 > |____________________________________________________________________ > > Next this is what i want it to look like once that works > (im going to have it check for how many words there are and for ever > word it creates The (First, Second, Third, Etc) word you entered was > _______ > and for the first, second, third, etc it will be the same var as the var > stating the array number like > i =+1 > word[i] > so that the numbers will be the same and then it will add 1 for ever > word > ____________________________________________________________________ > > |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 a = ["fifth", "fourth", "third", "second", "first"] print "Gimme wordz: "; gets.chomp.split.each { |w| puts "The #{a.pop} word is #{w}" } Seriously though, try to break your problem into as little of units as possible, and try to solve each one by playing around in irb and using the online docs (links follow) if you don't have hard copies. I especially recommend you read about blocks, and look at the various methods in class "Array". http://www.whytheluckystiff.net/ruby/pickaxe/ http://www.ruby-doc.org/ -d -- darren kirby :: Part of the problem since 1976 :: http://badcomputer.org "...the number of UNIX installations has grown to 10, with more expected..." - Dennis Ritchie and Ken Thompson, June 1972