0

Trying to calculate how old the user was when Trump got elected.

 def trump prompt
   year_born = trump(prompt)
   year_born =  2016 - year_born.to_i
   return year_born.to_s
 end

 age_when_trump_elected = trump('what year were you born?')
 puts name + ' you were ' + age_when_trump_elected + ' years old when Trump got elected'
morissetcl
  • 544
  • 3
  • 10
ben
  • 1

1 Answers1

2

The issue is here:

def trump prompt
  year_born = trump(prompt)

in the first line of the method, you call itself again and again, recursively. The method calls allocate frames on the stack and sooner or later the stack gets exhausted.

What you want is probably to get the value from the user’s input:

def trump prompt
  print prompt
  year_born = gets.to_i
  ...
Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
  • 1
    Yeah, this makes more sense. Looks like I didn't really understand what he was trying to do – Viktor Aug 18 '19 at 10:23