hns
hns

Reputation: 9

How to check elements in a random numbers list in C

I have a list of randomly generated 50 numbers. If i want to check the list to see if there are any numbers above 15 in it, how it should be done on Arduino IDE?

This is how i am doing it, but not working:

 for (int x = 0 ; x < 50 ; x++)  
  {
    if(list[x]>=15) 
    digitalWrite(ledPin, HIGH);     //turn LED on 
    if(list[x]<15) 
    digitalWrite(ledPin, LOW);      //turn LED off 
  }

Please help!

Upvotes: 0

Views: 44

Answers (1)

J W
J W

Reputation: 61

If I am getting you right, you want the led to be turned on if there is at least one element higher than 15.

In this case I would do something like this:

digitalWrite(ledPin, LOW);      //turn LED off 
for (int x = 0 ; x < 50 ; x++)  
{
  if(list[x]>=15) 
  {
    digitalWrite(ledPin, HIGH);     //turn LED on 
    break;
  }
}

Upvotes: 1

Related Questions