Episode 8b - Things That Can Go Wrong With User Input

Exercises

  1. This program has a mistake and will display an error message if you run it:
    puts "Enter a number:"
    first_number = gets.chomp
    puts "Enter another number:"
    second_number = gets.chomp
    product = first_number * second_number
    puts "The product of the numbers is " + product
    This program has a mistake but does NOT display an error message if you run it:
    puts "Enter a number:"
    first_number = gets.chomp
    puts "Enter another number:"
    second_number = gets.chomp
    sum = first_number + second_number
    puts "The sum of the numbers is " + sum
    
    Describe in your own words why one program shows and error and the other doesn't even though there's a mistake in both.