
October 12th, 2011, 04:59 AM
|
|
Registered User
|
|
Join Date: Oct 2011
Posts: 1
Time spent in forums: 5 m 21 sec
Reputation Power: 0
|
|
|
Newbie! i cant arrange the output properly
just a bit of polish work needed.. ive been working on this program for three days i just started ruby yesterday and need a little help.
command = ""
names = []
while command != "exit"
puts 'please enter names seperated by a space: '
command = gets.chomp!
if command == "quit"
names.sort! do|a,b| a.upcase <=> b.upcase end # use {...} for do\end, in a single entry rather then multiple
names.each_with_index do |name, index|
if index % 2 == 0
puts "#{name}", "\n"
else
puts "#{name.reverse}", "\n"
end
end
else
names << command
end
end
so what this progam does is display a number of names that where entered by the user. what i cant get it to do is display the names under each other. eg. rob bill lucy chop ... its then to display every second name backwards and to display them under like this
rob
bill
lucy
chop
======
llib
pohc.
lolmy brain is cooked any suggestions??
|