# conditionals.rb -- Tests of if, unless, and case statements 
# 

secret_int = 7
 
print "Guess the secret integer (range [1,10]): "
a = gets.to_i
puts "Your guess is #{a}"

if a == secret_int
  puts "Congratulations! Your guess is correct!"
elsif a < secret_int
  puts "Sorry, your guess is too small"
else
  puts "Sorry, your guess is too large"
end

puts
puts "Now enter two strings of lowercase letters, one per line:"
print "  String 1: "
str1 = gets.chomp
print "  String 2: "
str2 = gets.chomp

puts "The strings you entered were #{str1} and #{str2}"
puts
puts "Compare strings using normal relational operators:"

if str1 < str2
  puts "  #{str1} is less than #{str2}"
elsif str1 == str2
  puts "  #{str1} is equal to #{str2}"
else
  puts "  #{str1} is greater than #{str2}" 
end

puts "Compare strings using case construct with spaceship operator (<=>):"

case str1 <=> str2
  when -1
    puts "  #{str1} is less than #{str2}"
  when 0
    puts "  #{str1} is equal to #{str2}"
  else
    puts "  #{str1} is greater than #{str2}" 
end

puts "Compare strings using case construct with boolean expressions:"

case
  when str1 < str2
    puts "  #{str1} is less than #{str2}"
  when str1 == str2
    puts "  #{str1} is equal to #{str2}"
  else
    puts "  #{str1} is greater than #{str2}" 
end
