need help fixing code to function properly

The piezo keeps beeping even tho the LED sending light to the photo resistor is disconnected. i need the piezo to only beep whenthe led had blinked to the photo resistor.

int randomNumber;
int piezo=2;
int led=3;
int photo=A0;
void setup() {
  pinMode(led,OUTPUT);
  pinMode(piezo,OUTPUT);
  pinMode(photo,INPUT);
randomSeed(analogRead(0));
Serial.begin(9600);
}


void loop() {
randomNumber=random(7);
delay(1000);
int readpiezo;
int count=0;
Serial.println(String(randomNumber));
for (int i=0; i<randomNumber; i++){
digitalWrite(led,HIGH);
delay(350);
readpiezo=analogRead(photo);
if (readpiezo>1000){ count++;}
Serial.println(String(readpiezo));
digitalWrite(led,LOW);
delay(350);
readpiezo=analogRead(photo);
Serial.println(String(readpiezo));
}

for(int j=0; j<count;j++){
tone(piezo,330,100);
delay(300);
noTone(piezo);
delay(300);}
}

How many times are you going to post the same question? It only annoys people and may get you less help not more.

Steve

Maybe you need to adjust your detection threshold for the photoresistor?