TITLE: Prove that no function exists such that...
QUESTION [8 upvotes]: 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.

REPLY [2 votes]: 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 $.