I am writing a recursive function that seems to work, but I have to also include a while loop to ask the user for the depth of the recursion. This is resulting in an endless loop.
Here is the code:
Any ideas on how to break from this while loop?Code:void recurse(int count, int depth); // function prototype int main() { int depth; cout << "Please enter a number for recursion depth, or -1 to exit: " << endl; cin >> depth; while (depth != depth *2) { for (int counter = depth -(depth * 2); counter <= depth; counter++) { recurse(counter, depth); } cout << "Please enter a number for recursion depth, or -1 to exit: " << endl; } return 0; } void recurse(int count, int depth) { if (count < 0) cout << "This was written by call number " << (count * -1) << "." << endl; else if (count > 0) cout << "This was ALSO written by call number " << count << "." << endl; else if (count == depth) return; }