Adding lengths of strings together in Ruby

Posted by ppreyer on Stack Overflow See other posts from Stack Overflow or by ppreyer
Published on 2012-06-07T22:36:40Z Indexed on 2012/06/07 22:40 UTC
Read the original article Hit count: 454

I'm trying to write a program that takes the length of my first, middle, and last names individually and then adds the total amount of letters up in the end. My answer keeps on being 666 instead of 18. Here is the code I have written:

puts 'What is your first name?' firstName = gets.chomp realFirstName = firstName.length.to_i puts 'What is your middle name?' middleName = gets.chomp realMiddleName = middleName.length.to_i puts 'What is your last name?' lastName = gets.chomp realLastName = lastName.length.to_i puts 'Did you know there are ' + realFirstName.to_s + realMiddleName.to_s + realLastName.to_s + ' letters in your name?'

Just wondering where I went wrong.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby