Im trying to make a program that generates all the verses of the song "The Twelve Days of Christmas" using recursion (its homework). Ive read what the book says several times, researched online, etc etc. Im not looking for anyone to do the homework for me...I just need some guidance. Im really lost on this and any help would be appreciated.

I cant use for loops or while loops.
I can only have lines from each verse appear only once in the code.

6 Years
Discussion Span
Last Post by jen5376

In recursion you need a "base case". Here I guess the base case is the first line of the song. So your function should probably be called PrintAllPreviousVerses(int verse) and just call it recursively decrementing 'verse' by 1. This actually doesn't seem like an ideal case to teach recursion, but maybe I just don't know what I'm talking about :)


OK, this might be considered cheating and would probably be the worst-basic-solution, but here goes nothing:

Can't you store the verse's in a 2-d array, word-wise then increment index using recursion?

char arr[][50]={"Word1","Word2"...};

Edited by nbaztec: n/a


I'd use a std::vector<std::string> no matter how you plan to do the recursion.

I'd echo on that, it will make your problem simpler.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.