Dev-cpp comes with an example program Jackpot, which has a GetResults function in it:
void
GetResults ()
{
.
.
.
else if (i>j)
{
cout << "Too BIG\n";
life = life - 1; // -1 to the user's "life"
cout << "Number of remaining life: " << life << "\n\n";
GetResults();
}
Is this an elegant way of repeatedly asking for user input? Sure it is more readable than wrapping the ~20 lines around with a do-while
loop. I tend to like it but I don't see such a thing often, so I'm not sure. What's your opinion?
EDIT: In your example, recursion depth is prevented by the number of lives, so that seems OK as this won't get bigger than 1000 or even 100 - this is exactly why I have considered it, but now I can see it was a rather stupid idea :) I wonder who put this in an example program...
Thanks for the input guys!