Stuck in a simple function programming

Hi,
I am a green hand and want to write a function in my program but when I verify it, it shows that the function definition is not allowed here before '{'
token as the attached screenshot shows.
This is the code:

  int applyDeadband(int InputData,int Limit) 
  {
    if (abs(InputData) < Limit) InputData = 0;
    else if (InputData> 0) InputData -= Limit;
    else InputData += Limit;
    return InputData;
   }

Could anyone give me a clue why it is wrong?
Thx!

???? 2014-02-26 ??2.07.05.png

Your return needs a ;

return InputData;

JimboZA:
Your return needs a ;

return InputData;

Yes, thanks. I missed it when I upload the picture. I'll edit my post a bit....
But problem still occurs after adding ';'
I can't figure out why.

Post a bit more (read as: all of your 8) ) code; the problem might be just above that function?

JimboZA:
Post a bit more (read as: all of your 8) ) code; the problem might be just above that function?

It's a very long program I adapt from others. Itself is OK but once I add that very simple function it turns out to be wrong...
So the problem should only with that function and when I compile the cursor stops at the front of the first '{' token and indicates the function definition goes wrong.

aaarthur:

JimboZA:
Post a bit more (read as: all of your 8) ) code; the problem might be just above that function?

It's a very long program I adapt from others. Itself is OK but once I add that very simple function it turns out to be wrong...
So the problem should only with that function and when I compile the cursor stops at the front of the first '{' token and indicates the function definition goes wrong.

JimboZA is correct in assuming your problem lies elsewhere in your code. The function you posted compiles without problem for me.

Post the few lines above it..... I'm guessing a previous line wasn't terminated or something.

The problem is almost certainly caused by the fact that the function is defined within another one.

Putting each brace on its own line and using Auto Format in the IDE will either show up the problem because the indenting will be wrong or Auto Format will not work because of too many left curly braces (at a guess).

Post all of the code here if you cannot sort out the problem yourself.

UKHeliBob:
The problem is almost certainly caused by the fact that the function is defined within another one.

Yep that's sort of what I was thinking: OP might have put this function just above the closing } of loop() for example....

JimboZA:

UKHeliBob:
The problem is almost certainly caused by the fact that the function is defined within another one.

Yep that's sort of what I was thinking: OP might have put this function just above the closing } of loop() for example....

Yes, you are quite right!!!
Previous and afterward part is a very long function, and I mistakenly write within the function without realization.
Thanks guys!!! You all help me out!

The Moral of the Story.... post all code not just the part where it seems the problem might be.