microsecondsToCentimeters' was not declared in this scope

Hello
I have some problem
It's my code:

#include <Servo.h>
Servo servo;
Servo servo1;
int pos = 0;  
const int TrigPin = 12;
const int EchoPin = 13;

void forward() 
{
 servo.write(0);
 servo1.write(0);
}



void setup() {
 Serial.begin(9600);

 pinMode(TrigPin, OUTPUT);
 pinMode(EchoPin, INPUT);
 
servo.attach(9); 
servo1.attach(10);

}

void loop() {
 long duration, inches, cm;
{            
 forward();             
 delay(2000);
}
 digitalWrite(TrigPin, LOW);
 delayMicroseconds(2);
 digitalWrite(TrigPin, HIGH);
 delayMicroseconds(5);
 digitalWrite(TrigPin, LOW);


 duration = pulseIn(EchoPin, HIGH);
 cm = microsecondsToCentimeters (duration);

 Serial.print(cm);
 Serial.print("cm");
 Serial.println();

 if (cm < 80)
 for(pos = 0; pos < 90; pos += 1)  

 {                        
   servo.write(pos);             
   delay(50);   
   servo1.write(pos);             
   delay(50);   
 }

 for(pos = 90; pos>=1; pos-=1)    
 {                               
   servo.write(pos);             
   delay(50);  
   servo1.write(pos);             
   delay(50);      
}



long microsecondsToCentimeters(long microseconds) {
 return microseconds / 29 / 2;
}

And the error is:

exit status 1
'microsecondsToCentimeters' was not declared in this scope

Where does loop() end? You can NOT have a function defined in another function (loop()).

You have useless curly braces and missing, essential, curly braces.

If you use the auto indent feature of the IDE (ctrl-t or Tools, Auto Format) you will see that you are missing a curly bracket to close the loop() function.

Please read the "how to use this forum-please read" stickies to see how to post code.

If you read the post on page 1, the one that says "Read this before posting a programming question ... " and enclose you code in tags, put it in a nice, colour-coordinated editor, you'll quickly see that you're missing a closing brace for your loop function.

Now, depending on where you place that brace, the microsecondsToCentimeters() function is either inside or outside the loop(). If inside, you are violating standard C as functions within functions are not allowed. An extension to GCC however, does permit this but the function should be placed at the top of the loop, i.e. declare it before you use it.

You place it outside the loop (proper C) and you can put it wherever you want, but should also be before you use it. Arduino lets you get away with placing it anywhere as function prototypes are built on your behalf. Proper form suggests that you place the function above its first use or at least declare its prototype near the top of your code.

The code you posted generates this error for me:

sketch_jun25a.ino: In function 'void loop()':
sketch_jun25a:67: error: a function-definition is not allowed here before '{' token
sketch_jun25a.ino:28:18: warning: unused variable 'inches' [-Wunused-variable]
sketch_jun25a:69: error: expected '}' at end of input
a function-definition is not allowed here before '{' token

The error you posted seems to be for another version of the code, or using another compiler
from the standard Arduino IDE?

Try this modified code

#include <Servo.h>
Servo servo;
Servo servo1;
int pos = 0;
const int TrigPin = 12;
const int EchoPin = 13;

void forward()
{
  servo.write(0);
  servo1.write(0);
}



void setup() {
  Serial.begin(9600);

  pinMode(TrigPin, OUTPUT);
  pinMode(EchoPin, INPUT);

  servo.attach(9);
  servo1.attach(10);

}

void loop() {
  long duration, inches, cm;
 
  forward();
  delay(2000);
 
  digitalWrite(TrigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(TrigPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(TrigPin, LOW);

  duration = pulseIn(EchoPin, HIGH);
  cm = microsecondsToCentimeters (duration);

  Serial.print(cm);
  Serial.print("cm");
  Serial.println();

  if (cm < 80) {
    for (pos = 0; pos < 90; pos += 1)  {
        servo.write(pos);
        delay(50);
        servo1.write(pos);
        delay(50);
    }

    for (pos = 90; pos >= 1; pos -= 1) {
        servo.write(pos);
        delay(50);
        servo1.write(pos);
        delay(50);
    }
  }
}


long microsecondsToCentimeters(long microseconds) {
  return microseconds / 29 / 2;
}