TITLE: Construct a continuous real valued function which takes zero on integers and such that image of function is not closed.
QUESTION [8 upvotes]: I am trying to construct a continuous real valued function $f:\mathbb{R}\to \mathbb{R}$ which takes zero on all integer points(that is $f(k)=0$ for all $k\in \mathbb{Z}$) and Image(f) is not closed in $\mathbb{R}$
I had $f(x)=\sin(\pi x) $ in mind. But image of $f(x)$ is closed. 
I have a feeling that we can use some clever idea to modify this function such that it satisfy our given condition.

REPLY [2 votes]: Consider
$$f(x) = \sin^2 (\pi x)\frac{x^2}{1+x^2}.$$
Then $f$ is continuous, $f=0$ on the integers, but $f(\mathbb R) = [0,1).$