the code below will put names into groups (e.g. first person goes into first group, second person goes into second group etc).
I'd like to enter the final piece of code and request user to input the number of the group. This should then print the people in that group, each separated by a comma and a space. Group numbers are "1-indexed". This means that, if the user enters 1, the first group should be printed, not the second group. Keep on asking the user for (final) group numbers until the user enters stop.
puts "How many groups would you like?"
group_num = gets.chomp.to_i
array = Array.new(group_num) { [] }
puts "Enter one name at a time"
count = 0
while input_name = gets.chomp
if input_name == "stop"
break
else puts "Give me a name"
array[count] << input_name
count += 1
count = 0 if count == group_num
end
end
array.inspect
So if array = [["John", "Steve"], ["Judy", Pete"]] and the group number requested is 2, the output should print: "Judy, Pete" (on the same line).