Find all continuous functions $f:X\rightarrow \mathbb{R}$ such that $f^2=f$. 
Let ($X,\mathcal{T}$) be a topological space. Find all continuous
  functions $f:X\rightarrow \mathbb{R}$ such that $f^2=f$.

[ Note after the discussion in the comments: $f^2$ is the function $f^2:X\rightarrow\mathbb{R}$ defined by $(f^2)(x)=(f(x))^2$ for every $x\in X$. ]
The hypothesis gives us that $f=0$ or $f=1$. 
At what points of $X$ will $f$ take the value $1$?

$$f^2=f\iff f(f-1)=0\iff f=0\text{ or }f= 1.$$
Such functions are in bijection with the partitions of your space into two unions of connected components.
