Prove that no function exists such that... The exercise goes like this:


*

*Find a continous function $f:\mathbb{R} \rightarrow \mathbb{R}$ such that $\forall c \in \mathbb{R}$ the equation $f(x)=c$ has exactly 3 solutions;

*Prove that no continuous function $f: \mathbb{R} \rightarrow \mathbb{R}$ exists such that the equation $f(x)=c$ has exactly two solutions $\forall c \in \mathbb{R}$;

*For what $n \in \mathbb{N}$ it's true that a continous function $f:\mathbb{R} \rightarrow \mathbb{R}$ such that $\forall c \in \mathbb{R}$ the equation $f(x) = c$ has exactly $n$ solutions exists?


For the first point I built kind of a zigzag function which is easily generalizable to every odd $n$. It seems true to me that for even natural numbers such a function doesn't exist, because in some ways it would have to "jump", but I failed to formalize the argument. 
 A: Point two: Suppose such a function exists. We note that the function has to be surjective and has to have two roots (i.e. points $a_1$ and $a_2$ such that $f(a_1,a_2)=0, a_1<a_2$ without loss of generality). In the interval $]a_1,a_2[$ the function has to have constant sign (suppose it doesn't, since the function is continuous there have to be another root, contradicting what we said earlier). Moreover, since by the Weierstrass theorem the function is limited in $[a_1,a_2]$ the signs before $a_1$ and after $a_2$ have to be opposite, since otherwise the function wouldn't be surjective. Suppose now that the function is $>0$ in the interval $[a_1,a_2]$ (it isn't restrictive since the argument is easily replicable if it isn't). The function can't be constant in the interval, since if it is then there are infinite points for which the function takes the constant value and we have a contradiction. Let's take then any point in the interval which isn't a maximum. We also note that if a point is a maximum it can't be zero, so it has to be in the internal part of the interval. There are, by our hypothesis, at most two points in which the function takes a maximum ($m_1$ and $m_2$, $m_1<m_2$). Let's call the two intervals $[a_1,m_1]$ and $[m_2,a_2]$. Inside the intervals, the function has to take every value between $0$ and $f(m_1)=f(m_2)=M$. So for every point in $[a_1,m_1]$ and $[m_2,a_2]$ there are two roots. But since in the interval $[a_2,+\infty[$ (but it could be in $]-\infty,a_1]$, the argument wouldn't change) the function takes every value between $0$ and $\infty$, thus we have found another root and a contradiction.
Maybe this is generalizable (please report any mistake whatsoever).
A: We assume that $ f$ is continuous and that the equation $ f (x)=c $ always has at least two solutions, and find a $ c $ for which the equation has at least three solutions. 
Suppose $ f (x_1)=f (x_2)=0$ for $ x_1 <x_2$. Since $ f $ is continuous, it is bounded on $[x_1, x_2] $, and attains its maximum.  Let this maximum be $ M$. Assume for now that $ M> 0$, and let $ m\in [x_1, x_2] $ satisfy $ f (m)=M $.
By the intermediate value theorem, there must be $ m_1$ and $ m_2$ such that $ f (m_1)=f (m_2) =M/2$  and satisfying
$$ x_1 <m_1 <m <m_2 <x_2. $$
Now consider an $ n $ such that $ f (n)=2M$. We know that $ n\notin [x_1, x_2 ] $ so without loss of generality assume that $ x_2<n $.  Applying the IVT again, there must be a solution to $ f (x)=M/2$ in the interval $[x_2, n] $. But that means we have at least three solutions to $ f (x) =M/2$.
If $ M=0$, you can apply the same argument to $-f $.
