Prove $[ (-1)^{⌊x⌋+⌊\frac{x}{n}⌋}~\cdot~(x-⌊x⌋-\frac{1}{2}) ]+ ⌊\frac{x}{n}⌋ + \frac{1}{2}$ is continuous if $n$ is odd. This comes from problem 21c of Chapter 7 of Spivak's Calculus 4th Edition.
21c) Find a continuous function $f$ which takes on every value exactly $n$ times, where $n$ is odd.
The solution I came up is $f_n(x)= [ (-1)^{⌊x⌋+⌊\frac{x}{n}⌋}~\cdot~(x-⌊x⌋-\frac{1}{2}) ]+ ⌊\frac{x}{n}⌋ + \frac{1}{2}$
Where $⌊x⌋$ is the floor function.
It seems to work, but I want to prove it works. Well atleast I want to prove it is continuous on $\mathbb{R}$. No idea where to start. Any suggestions?
 A: Continuity of $f_n$
For $x \in [kn + i, kn+i + 1)$ with $(n,i) \in \mathbb Z \times \{0, \dots, n-1\}$ you have $\lfloor x \rfloor = kn+i$, $\lfloor \frac{x}{n} \rfloor = k$ and
$$\begin{aligned}f_n(x) &= \left[(-1)^{k(n+1)+i}\left(x-kn-i -\frac{1}{2}\right)\right] + k + \frac{1}{2}\\
&= \left[(-1)^{i}\left(x-kn-i -\frac{1}{2}\right)\right] + k + \frac{1}{2}
\end{aligned}$$ and therefore for $x \in [kn + i, kn+i + 1)$
$$f_n(x) = \begin{cases}
x-kn-i+k &\text{ for } i \text{ even}\\
-x+kn+i+k+1  &\text{ for } i \text{ odd}
\end{cases}$$
Based on that we get for $i$ even
$$\lim\limits_{x \to (kn+i+1)^-} f_n(x)= k+1 = f_n(kn+i+1)$$ and for $i$ odd
$$\lim\limits_{x \to (kn+i+1)^-} f_n(x)= k= f_n(kn+i+1).$$
Knowing that $f_n$ is continuous on all intervals $(kn + i, kn+i + 1)$, this allows to conclude that $f_n$ is continuous on each interval $(kn, k(n+1))$ with $k \in \mathbb Z$. As
$$\lim\limits_{x \to kn^-} f_n(x)=k= f_n(kn)$$ we can finally conclude that $f_n$ is continuous on $\mathbb R$.
Values taken by $f_n$

*

*$g_n(x)=f_n(x) - ⌊\frac{x}{n}⌋$ is a periodic map with $n$ as a period.

*$g_n$ takes exactly $n$ times each value of $(0,1)$ on the interval $(0,n)$.

*The cardinal of $f^{-1}_n(\{0\})$ is equal to $n$.

*For all $x \in \mathbb R$ $f_n(x+n) = f_n(x)+1$.

*Conclude.

This can also be seen directly from the study of the continuity and the values taken on each interval on which $f_n$ is linear.
