While loops in parallel

I am new to arduino and i have a problem in this code. I have two sonar sensor hc-04 which i am using to find a obstacle in the path.
But the problem is i have to place sonar sensors in a straight path having some distance between them and something will cross the path
I have to detect that thing and detection will be done when both sensors has acknowledged that the thing has crossed
Problem is i am not be able to write a code which does that
I have try a method using flags such that when sensor 1 is true flag is high and it waits for sensor 2 to be true but it is not working
Kindly help me as soon as possible here is the code

const int trigpin=9;
const int echopin=10;
const int trigPin=11;
const int echoPin=12;
int flagA=0;
int flagB=0;
unsigned long cTime=0;
unsigned long pTime=0;
int interval = 15000;
void setup() {

pinMode(trigpin,OUTPUT);
pinMode(trigPin,OUTPUT);
pinMode(echopin,INPUT);
pinMode(echoPin,INPUT);
// pinMode(tpin,OUTPUT);
// pinMode(epin,INPUT);
Serial.begin(9600);

}
void loop()
{
int x,y,z;
x = calculateDistance(trigpin,echopin);
y = calculateDistance(trigPin,echoPin);
// z = calculateDistance(tpin,epin);

Serial.print("Distance X:");
Serial.print(x);
Serial.println();
Serial.print("Distance Y:");
Serial.print(y);
Serial.println();

if ( x > 1 && x <= 40)
{
flagA = 1;
cTime = millis();
Serial.println(cTime);

if ( flagA==1 && y <= 40)
{
Serial.print(cTime - pTime);
if ( (cTime - pTime) < 2000)
{Serial.println("basket"); }
pTime = cTime;
flagA = 0;
}
else
{
pTime = cTime;
flagA = 0;
}
}
delay(1000);
}

double calculateDistance( int trigpin, int echopin )
{
double duration, distance;
digitalWrite(trigpin,LOW);
delayMicroseconds(2);
digitalWrite(trigpin,HIGH);
delayMicroseconds(10);
digitalWrite(trigpin,LOW);
duration = pulseIn(echopin,HIGH);
distance = (duration/2)/29.4;
return distance;
}

You have asked your question in a 5-years dead Thread. I have suggested to the Moderator to move it to its own Thread.

To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

And can you tell us exactly what happens when you run your program as well as what you want it to do that is different.

You may get some ideas from the demo Several Things at a Time but I confess that at this stage I do not understand what your problem is.

...R