Need help on the IF-statement

  Serial.println("cm");
}

That closing brace ends your loop function. The compiler is complaining that the code that follows isn't in any function. Move the brace to the end. You have a number of additional braces in there that are unnecessary too.