This is a common mistake. What your code does is simply checking whether the first element of the array is equal to the
value. What you wish is to iterate over the whole array. But after checking the first element of the array, you simply give it a choice to return
false if the the element you were searching for is not found. Instead, you should do something like this.
bool found = false;
for (int i = 0 ; i < n ; ++i)
if (values[i] == value)
found = true;
The fact to be considered here is that the
value you are searching for may reside not necessarily on the first element(0th index) of array.
I have put the
break statement as it is useless to search for the
value in the rest of the array once it has been found, so that doesn't make a difference as you shall be returning
true at last. Here,
break optimizes this code, but not changes the time complexity.
Hope that helps.