Proving a set of a subset of the range of a function has a maximum I have a homework question which is:

$f(x)$ is continuous on $(0,1)$ , $\underset{x\to 0+}{\mathop{\lim
 }}\,f(x)=-1$ and $\underset{x\to 1-}{\mathop{\lim }}\,f(x)=1$
Let $A=\{x\in(0,1)|f(x)=0\}$. We will mark $\operatorname{sup} A = s$. 
prove that $f(s)=0$.

Obviously this means we need to prove that $A$ has a maximum. I find this fairly reasonable and intuitive and I think I might have written a correct proof but I am sure there is a much better way to do it then what I have tried. 
Could someone please help me with this question? Thanks :)


EDIT: This is what I did roughly lined out:
1)Because of the limits exists a left area of 1 where $f(x)>0$ and a right area of $0$ where $f(x)<0$
2) choose $y_0$ and $y_1$ in those areas so and use the interval $[y_0,y_1]$ to show that $A$ is a subset of $[y_0,y_1]$ which is a subset of $(0,1)$
3)$y_1$ is that maximum of $[y_0,y_1]$ but does not belong to $A$ because $f(y_1)>0$ so choose the first $x$ in $A$ which is smaller then that and that is the maximum of $A$.
4) because $A$ has a maximum then s is equal to it and then also $f(s)=0$
What do you guys think?
 A: By the limit conditions, there exists $ \epsilon > 0 $ such that $A \subseteq [\epsilon, 1-\epsilon].$ Consider $g$, the restriction of $f$ onto this set. Since $g$ is continuous and $ \{ 0 \} $ is a closed set, $ g^{-1} ( \{ 0\} ) = A $ is closed in $ [\epsilon, 1-\epsilon],$ i.e $A$ contains the limit of any sequence in $A$, and since $ \sup A $ must be the limit of some sequence in $A$ we have $ \sup A \in A.$
This would be the other way to go, as Martin said in the comments to his answer.

A useful lemma for the elementary supremum properties is this: Let $A$ be bounded from above so that $s=\sup A$ exists. If $t$ is a real number such that $t< s,$ then there exists an element $a \in A$ such that $t<a.$ Using this fact we can inductively construct a sequence of elements in $A$ which tend to $\sup A$. Let $a_1 $ be an element such that $ s-1 < a_1.$ Let $ a_2 $ be an element $ a_2 > \max \{ s-1/2, a_1 \} $, and $a_3$ be an element such that $ a_3 > \max \{ s-1/3, a_2 \}$ and so on. Can you see why i) we can always pick such elements, ii) this sequence is increasing and bounded, and thus has a limit, iii) why the limit is $\sup A$ ? 
Once you know there is a sequence of elements in $A$ which tends to $\sup A$, use this characterization of continuity (if you haven't this before it is a good exercise to try to prove it): If $f$ is continuous and $ a_n \to L$ then $ \lim_{n\to\infty} f(a_n) = f(L).$  
A: Note that the assumptions about your function imply that $A\ne\emptyset$. (Do you know why?)
There are two possibilities:


*

*Either $s\in A$ and then clearly $f(s)=0$.

*Or $s=\operatorname{sup} A\notin A$. 
Can you show in the second case that there is a sequence
$(a_n)$ of elements of $A$ such that $a_n\to s$? Can you use this finish the proof? (Does the fact that $f$ is continuous help? If $f$ is continuous and $a_n\to s$, what can you say about the sequence $f(a_n)$?) 

Other possibility would be to show that the set $A$ is closed. As $A\subseteq[0,1]$, it is also bounded. Hence $A$ is compact and every compact subset of $\mathbb R$ has a maximum.

To be sure that you understand the proof, it might be useful to you to try to find an example of function, which is not continuous and for which the claim fails. (It may help you understand better at which point of your proof continuity was used.)
