what is wrong with this code?

So I’m trying to write a program that makes a Light go on when the distance is less than X inches but, also make a servo sweep when the distance is more than than X inches. However I got a weird error saying a function_definition is not allowed here before “{” token please help me fix this code

#include <Servo.h>
Servo myservo;

const int pingPin = 7;

int pos = 0;
int shoot = 8;
void setup() {
  
  Serial.begin(9600);
  myservo.attach(9);
  pinMode(shoot, OUTPUT);
}

void loop()
{
  
  long duration, inches, cm;

 
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

 
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);

 
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
 
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  
   if(inches >= 84 && inches <= 6)
  {
  for(pos = 0; pos < 90; pos += 1);
  {
    myservo.write(pos);
    delay(15);
  }
  for(pos = 90; pos>=1; pos-=1)
  {                                
    myservo.write(pos); 'pos';
    delay(15);
    
    if(inches <= 84 && inches >= 6)
    digitalWrite(shoot, HIGH);
    delay(10000);
    digitalWrite(shoot, LOW);
    
  }
 
  delay(100);
}

long microsecondsToInches(long microseconds)
{ //This line is the one giving me troble
  
  return microseconds / 74 / 2;
}

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

You are missing a closing brace. Likely the one associated with this:

   if(inches >= 84 && inches <= 6)

Ok, thanks that fixed it :). I dident even realize I left that out

if(inches >= 84 && inches <= 6)

For what value of inches will this ever be true?

PaulS:

if(inches >= 84 && inches <= 6)

For what value of inches will this ever be true?

None :smiley: I was more focused on showing him proper use of && Vs “and” that he was using, and I failed to proof the logic of his statement. He of course needs to perform a “or” instead of a “and”.