PDA

View Full Version : Doing Math With Variables


Tony_G.
August 5th, 2006, 11:15 PM
Hello :D I'm very new to coding and I'm having a little problem.

I'm trying to just create a very simple program that subtracts two variables. I can't get it to work, though. I've tried a zillion different things, but this was my last attempt:

puts 'Please enter the year of your birth:'

ydob = gets.chomp

puts 'Please enter the current year:'

currentyear = gets.chomp

puts 'It has been ' currentyear-ydob ' years since your birth.'


How, how, how, HOW do I get the variables to subtract? I've tried everything I could think of.

motobass
August 6th, 2006, 01:31 PM
Because 'puts' will place a new line after each, you can try print like this:


print "It has been ", currentyear-ydob, " years...\n"


Or this will work too:


puts "It has been #{currentyear-ydob} years..."