diff --git a/Nth-Fibonacci/Ruby/JHero23/app.rb b/Nth-Fibonacci/Ruby/JHero23/app.rb new file mode 100644 index 0000000..1005e84 --- /dev/null +++ b/Nth-Fibonacci/Ruby/JHero23/app.rb @@ -0,0 +1,32 @@ +# Declare a method/function that creates the fibonacci sequence +def fibonacci(num) + if num < 0 + return "Negative number not implemented yet" + elsif num <= 1 + return num + else + return fibonacci(num - 1) + fibonacci(num - 2) + end +end + + +begin + # Prompt the user + print "Enter a number: " + input = gets.chomp.to_i + + p "Your number is #{input}" + + # Generate the Fibonacci sequence + num_list = [] + + begin + num_list.push(fibonacci(input)) + input -= 1 + end while input.to_i >= 0 + + p "Your fibonacci numbers are #{num_list}" + + print "\nWant to try again? " + ans = gets.chomp.downcase +end while ans == 'y' || ans == "yes"