Help with robot code

so my old ping sensor died and my gf bought me a new one but with 4 pins and so i have revamped my code but it isnt working it sends distance back but for some reason it doesnt stop or turn when its danger thresh hold is reached i think the bug is in the if statements but im not sure

#include<Servo.h>

const int trigPin = 4;
const int echoPin = 2;
const int RForward = 180; //full speed forward
const int RBackward = 0; //full speed reverse
const int LForward = RBackward; //this decides the motor control
const int LBackward = RForward; //this decides the motor control
const int RNeutral = 90; //nuetral for motor
const int LNeutral = 90; //nuetral for motor
const int dangerThresh = 4; //threshold for obstacles (in)
int leftDistance, rightDistance; //distances on either side
Servo panMotor;  //this is the "neck" of the robot
Servo leftMotor; //declare left servo motor
Servo rightMotor; //declare right servo motor

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  rightMotor.attach(5); //attach right servo motor to proper pin
  leftMotor.attach(6); //attach left servo motor to proper pin
  panMotor.attach(3); //attach pan servo motor to proper pin
  panMotor.write(90); //center the "neck" of the robot
  delay(50);
}
void loop() 
{
   
  int distanceFwd = ping(); //tells the robot distance forward
  if (distanceFwd>dangerThresh) //if path is clear
  {
    leftMotor.write(LForward); //move forward
    rightMotor.write(RForward); //move forward
  }
  else //if path is blocked
  {
    leftMotor.write(LNeutral);  //stop forward motion
    rightMotor.write(RNeutral); //stop forward motion
    panMotor.write(0); // turn ping sesor right
    delay(500);
    rightDistance = ping(); //scan to the right
    delay(500);
    panMotor.write(180);  //turn ping sensor left
    delay(500);
    leftDistance = ping(); //scan to the left
    delay(500);
    panMotor.write(90); //return to center
    delay(100);
    compareDistance();  //determine the distance on both sides
    }
}
void compareDistance()
{
  if (leftDistance>rightDistance) //if left is less obstructed 
  {
    leftMotor.write(LBackward); //turn left
    rightMotor.write(RForward); //turn left
    delay(500); 
  }
  else if (rightDistance>leftDistance) //if right is less obstructed
  {
    leftMotor.write(LForward);  //turn right
    rightMotor.write(RBackward); //turn right
    delay(500);
  }
   else //if they are equally obstructed
  {
    leftMotor.write(LForward); //turn 180 degrees
    rightMotor.write(RBackward); //turn 180 degrees
    delay(500);
  }
}
long ping()  //ping sensor programming from library
{
    long duration, inches, cm;
 
  // The sensor is triggered by a HIGH pulse of 10 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(trigPin, OUTPUT);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
 
  // Read the signal from the sensor: a HIGH pulse whose
  // duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);
 
  // convert the time into a distance
  inches = microsecondsToInches(duration);
  //cm = microsecondsToCentimeters(duration);
  
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  
  delay(100);
}
long microsecondsToInches(long microseconds)
{
  return microseconds / 74 / 2;
}

I think that you need a return statement in ping() to give it a return value.

how would i do that because i thought

long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;

was the return measurement?

its a HC-SR04 ultrasonic sensor the previous sensor was a parralax PING(( sensor

long microsecondsToInches(long microseconds)
{
  return microseconds / 74 / 2;
}

Returns the value of the microsecondsToInches() to the inches variable. That does not give any value to ping() without a return inches at the end of ping().

ok ill try that

that seemed to fix the problem thanks