storing data to integer or something

I have a LED bar which i want to turn on and of by an distance sensor. at this moment when its on it will flicker on and off. I think that is because i didnt assign the distance as a general integer. Thats why i added it but, i dont know how to finish the global integer.
here’s the code:

#define trigPin 5
#define echoPin 6
int powerstate;
float duration;
int distance = (duration/2) / 29.1;
int reedpowerstate;

void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);  
pinMode(13, OUTPUT);
pinMode(8,OUTPUT);
powerstate = 0;

}

void loop() {
  
   long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  pulseIn(echoPin, HIGH);
  duration = pulseIn(echoPin, HIGH);
  get(distance);
  if (distance >= 50 && distance <=90) {
    if (powerstate = 0);{
       digitalWrite(13, HIGH);
       digitalWrite(8, LOW);
       analogWrite(11, 255);
       powerstate = 1;
       Serial.println(powerstate);
       delay(2000);}}
   
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  pulseIn(echoPin, HIGH);
  duration = pulseIn(echoPin, HIGH);
  get(distance);
  if (distance >= 50 && distance <=90) {
    if (powerstate = 1);{
       digitalWrite(13, LOW);
       digitalWrite(8, HIGH);
       analogWrite(11, 0);
       powerstate = 0;
       Serial.println(powerstate);
       delay(2000);}
       
  }
  delay(500);

}

Now you have two variables named distance. Google "C++ scope" and do some reading.

This line is a nonsense

int distance = (duration/2) / 29.1;

  get(distance); get() is not defined.

You're repeating code (the part where you take a distance reading). Put that in a separate function, makes your code a lot more readable and maintainable. You may save some precious memory in the process.