Code:
void indent ( int level )
{
for ( int i = 0 ; i < level ; i++ ) cout << " ";
}
void recurse ( int targetLevel, int level = 0, bool onTheWayBackDown = false)
{
indent( level );
if(level == targetLevel)
onTheWayBackDown = true;
if(!onTheWayBackDown)
{
cout << "This line was output by call " << level + 1 << "\n";
recurse(targetLevel, level + 1, onTheWayBackDown);
}
else
{
if(level == 0)
return;
cout << "This line was ALSO output by call " << level + 1 << "\n";
recurse(targetLevel, level - 1, onTheWayBackDown);
}
}
I haven't tested it, but I believe that should be pretty close to something that works.