Where does the loop() function end ?
It is difficult to see in your code, but if you select it the IDE and Auto Format it you will see that loop() has no end brace, hence the problem.
Once you have formatted it, if you post it here again please use code tags as described in read this before posting a programming question
which you either did not read or ignored.