a function-definition is not allowed here before '{' token

closed account (ozyMoG1T)

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
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
This might get you started...
You did not declare the function reverse in the correct spot.
See this for more info.

http://www.cplusplus.com/doc/tutorial/functions/

let me know if you have any questions.
Last edited on
Topic archived. No new replies allowed.