question archive Write, test, and debug (if necessary) a Ruby program with the following specification: Input: Three names, on separate lines, from the keyboard

Write, test, and debug (if necessary) a Ruby program with the following specification: Input: Three names, on separate lines, from the keyboard

Subject:Computer SciencePrice:2.89 Bought3

Write, test, and debug (if necessary) a Ruby program with the following specification:

Input: Three names, on separate lines, from the keyboard.

Output: The input names in alphabetical order. Do not use arrays.

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

# e153.rb - A solution to Exercise 15.3

# Get input

puts "Please type the three names, on separate lines"

name1 = gets

name2 = gets

name3 = gets

 

# Pass one - compare/interchange both pairs

if name2 < name1

 temp = name1

 name1 = name2

 name2 = temp

end

 

if name3 < name2

 temp = name2

 name2 = name3

 name3 = temp

end

 

# Pass two - compare/interchange the first two

if name2 < name1

 temp = name1

 name1 = name2

 name2 = temp

end

 

# Display results

puts "The names in order are: \n #{name1} #{name2} #{name3}"