I have an assignment to write a recursive function that writes the digits of a positive integer in reverse order. My problem is that the function doesn't display the reverse correctly. I know im supposed to use % or 10 when displaying the number and / of 10 when in the recursive call as well as the base case is supposed to be < 10. Here is my code.
#include <iostream>
using namespace std;
int reverse(int,int);
int main()
{
int number;
int n;
cout << " Enter number to reverse." << endl;
cin >> number;
cout << reverse(number % 10,0);
return 0;
}//end main
int reverse(int number,int n)
{
if(n < 10)
{
return n;
}
else
{
return reverse(number/10,n);
}
}// end reverse