Lines 18-39 are outside of the loop function. This is the cause of the compilation error.
Your if / else syntax is not correct. The correct syntax would be:
void loop() {
if(<condition 1>) {
// code if condition 1 is true
} else if(<condition 2>) {
// code if condition 1 is false, and condition 2 is true
} else {
// code if conditions 1 and 2 are both false
}
}
analogReference(DEFAULT); is a bit pointless, since it already has the default value when the program starts.
Finally, please read How to use this forum, use the IDE’s auto format function (CTRL+T) and make use of [code][/code] tags (</>) when posting code.