The obvious point of this exercise is to learn recursion, which is when a function calls itself, terminating when some barrier is reached. A symbol for this is the great worm Ouroboros who encircles the Earth, eating his tail. An interesting article about this is here: http://en.wikipedia.org/wiki/Ouroboros. The process potentially never ends... :-) Here is an example:
void recurse_until( int stop_when )
{
if (stop_when > 0)
{
recurse_until( stop_when - 1 );
}
return;
}
So, recurse_until() will keep calling itself until stop_when (the barrier) == 0, then then entire thing pops back to the original caller. This is, coincidentally enough (back to Ouroboros) called tail recursion.
If you do something like this, and each call where the barrier is > 0 you output a '*' before you call recurse_until() again, and a '$' after the call, you will get the results you want, with a single call from main() to recurse_until(), using the input number for the initial barrier value.
rubberman
Posting Maven
2,572 posts since Mar 2010
Reputation Points: 365
Solved Threads: 306
Skill Endorsements: 52