# Thread: help with a recursion function

1. ## help with a recursion function

thanks

2. I can actually answer someone elses question, if you want a loop, if you want it to be a true recursive call, this isn't it and I really CAN'T help you with recursion, really!

This code is in detail in the thread on prime numbers and stacks, but here is a shorter version:
Code:
```int main()
{
// variable declarations
//program banner - what the programs does and how
cin >> userResponse;    //the users responds  Y or y to continue, anything else to end

while (userResponse == 'Y' || userResponse == 'y')
{
cin >> userResponse;
}//end while
return 0;
}//end main```
as long as the user keeps answering the "do you want to go again" question with a Y or y (in this case), it will keep allowing use of the program. As soon as something (anything other than a Y or y) is entered the program terminates.

Hope this helps with the your problem.

Whether the user got the answer right or wrong, your functions should send control back to main and let main ask if they want to "do it again."

3. Generally, if something can be done easily with a loop, then do so. Recursion is an advanced technique that sucks up stack space everytime you use it.

4. . . . assuming that the compiler couldn't optimize the recursion into iteration. You'd be surprised at how often this happens.

That's not a good thing to depend upon, of course.

You're aware, of course, that these both do exactly the same thing?
Code:
```		!(mathTest());
mathTest();```

5. Code:
```    for(int index=1; index<=2; index++){
if (index == 1)
{
random_integerA = (rand()%10);
}
else
{
random_integerB = (rand()%10);
}
}```
Just a tip, I see no point in this, besides some wasted code. It works, of course, but the much more efficient way would just be this:
Code:
```random_integerA = (rand()%10);
random_integerB = (rand()%10);```
Also, maybe consider better indentation? (not horrible, but could be better)