[Solved] Checking all values in an array [duplicate]


You can check every element in the array and break if only the element is smaller than 100.

And outside the loop print the message based on whether i – The loop counter- is equal to the size or not. If equal than all elements are greater otherwise one of them is smaller:

int array[] = {271, 120, 469, 77, 2000};
//int array[] = {271, 120, 469, 787, 2000}; // uncomment this line and comment out the line above to see the difference.


int i = 0; 
for(; i < 5; i++)
    if(100 > array[i])
        break;

if(i != 5)
    std::cout << "Not all the values are greater than 100" << std::endl;
else
    std::cout << "All the values are greater than 100" << std::endl;

1

solved Checking all values in an array [duplicate]