Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 15th, 2012  |  syntax: None  |  size: 0.42 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Why is Ruby concatenating instead of adding 2 values?
  2. def add(x,y)
  3.   c = x + y
  4.   return c
  5. end
  6.  
  7. puts "please enter a value "
  8. a = gets.chomp
  9. puts "please enter another value "
  10. b = gets.chomp
  11.  
  12. printMe = add(a,b)
  13.  
  14. puts printMe
  15.        
  16. def add(x,y)
  17.   c = x + y
  18. end
  19.  
  20. puts "please enter a value "
  21. a = gets.to_i
  22. puts "please enter another value "
  23. b = gets.to_i
  24.  
  25. printMe = add(a,b)
  26.  
  27. puts printMe
  28.        
  29. def add(x,y)
  30.   (x.to_i + y.to_i)
  31. end