Sep 20, 2015 at 9:12pm UTC
I tried to run the program, it showed something like this:
In function 'int main()':
41:13: error: a function-definition is not allowed here before '{' token
57:62: error: 'reverse' was not declared in this scope
Can someone please help me to fix this problem?
Thank you.
Last edited on Sep 21, 2015 at 4:04pm UTC
Sep 20, 2015 at 9:21pm UTC
In future please keep all of this in 1 thread, you have 3+ separate questions about the same program.
http://www.cplusplus.com/forum/beginner/174084/
http://www.cplusplus.com/forum/beginner/174067/
1 2 3 4 5 6 7
int reverse( int number, int reverse_so_far = 0 )
{
if ( number < 0 ) return -reverse( -number ) ;
if ( number < 10 ) return reverse_so_far*10 + number ;
return reverse( number/10, reverse_so_far*10 + number%10 ) ;
}
You can't define a function inside another function, move it outside of main.
Last edited on Sep 20, 2015 at 9:23pm UTC
Sep 20, 2015 at 9:26pm UTC
Last edited on Sep 20, 2015 at 9:26pm UTC