"variable does not name a type
"The line with the error" falls outside of any functions. In C and C++ we write executable code inside functions. You placed your 

threshold=maxA0-40;


(and everything that follows) outside of any functions. Hence the error.

Errors like this are typically cased by improper placement of { and } braces. But this is something you have learn to check for yourself. Most C or C++ oriented code editors can usually help you with this. And proper code formatting can help you with this too. What you have now is such a mess, that a simple error is virtually impossible to see.