Fractional part, periodic function

I don't know how to solve this problem:

Let $f$ be a continuous real function such that $\{f(x)\} = f(\{x\})$ for each $x$

($\{x\}$ is the fractional part of number x)

Prove that then $f$ or $f(x)-x$ is a periodic function.

Could you help me?

-

The map $g\colon x\mapsto f(x+1)-f(x)$ is continous. Since $\{f(x+1)\}=f(\{x+1\})=f(\{x\})=\{f(x)\}$, the differnce $f(x+1)-f(x)$ must be an integer. So $g$ is a continuous map $\mathbb R\to \mathbb Z$, hence constant, i.e. we have a constant $w\in\mathbb Z$ such that $f(x+1)=f(x)+w$ for all $x\in \mathbb R$. This makes $f(x)-wx$ periodic with period $1$.
We have to show that $w=0$ or $w=1$. From $f(0)=f(\{0\})=\{f(0)\}\in[0,1)$ we conclude $f(1)=f(0)+w\in[w,w+1)$. For $x\in[0,1)$ we have $f(x)=f(\{x\})=\{f(x)\}\in[0,1)$, hence by continuity of $f$ $$f(1)=\lim_{x\to 1^-}f(x)\in[0,1].$$ The intervals $[w,w+1)$ and $[0,1]$ intersect if and only $w=0$ or $w=1$.$_\square$
OK, I'll try to modify to avoid this. Also I still need to show $w=0$ or $w=1$ (wtih some conditions not yet used). –  Hagen von Eitzen Jan 8 '13 at 16:23
@Anna As a general theorem: A continuous map from a connected space to a discrete space is constant. Specifically here: Assume $x\ne y$ with $g(x)>g(y)$. Then $g(x)\ge g(y)+1$, hence by IVT there exists $\xi$ between $x$ and $y$ with $g(\xi)=g(y)+\frac12\ne\mathbb Z$. –  Hagen von Eitzen Jan 9 '13 at 9:01