Although the above answers may be good for expert programmers, I believe at your level, Adkison, you would like a simpler response.
bool contains(Element e)
{
int i;
for(i=0;i<size;i++)
if(elements[i].getValue()==e.getValue()) return true;
else return false;
}
OK, so one problem is that elements doesn't have a value, and neither does size. It should be passed in as a parameter. We'll also use const-& on e, so that it need not be copied (although that's not a big cost here).
bool contains (const Element elements[], int size, const Element& e) ...
(Yes, we could pass in elements as a vector, but let's keep it simple for now.)
I believe the problem you're noting is that it never gets past looking at the 0th element. Trace through and you'll see why. Suppose that element #0 is equal to e; your function returns true, and is done. Suppose that it isn't equal: your function returns false, and is done. What about all the other elements? Shouldn't we check them too, at least if element #0 isn't what we wanted?
So: when should we return false? When when we've gone thru the whole list and not found e.
for(i=0;i<size;i++)
if(elements[i].getValue()==e.getValue()) return true;
return false;
This version doesn't return false until it's looked through the whole array, and failed to find e.