If $f$ is surjective, and $X$ is compact, then $f$ is not continuous: Pick $x_n \in X$ such that $f(x_n)=n$ for all $n \in \Bbb N$. (Does not even use the full force of surjectivity, btu it's all we need.)
As $X$ is compact, there is a point $p \in X$ such that for every open neighbourhood $O$ of $p$, $N(O):=\{n \in \Bbb N: x_n \in O\}$ is infinite. (This is called a point of complete accumulation of $\{x_n: n \in \Bbb N\}$.)
(Proof sketch : if no such $p$ exists, every $x \in X$ has an open neighbourhood $O_x$ with $N(O_x)$ finite. Take a finite subcover of $\{O_x: x \in X\}$ to derive a contradiction.)
Now take an open interval neighbourhood $I=(f(p)- \frac12, f(p)+\frac12)$ of $f(p)$. If $f$ were continuous at $p$ we'd have an open neighbourhood $O$ of $p$ such that $f[O] \subseteq I$, but then, for each $n \in N(O)$, $n = f(x_n) \in I$ and so $I$ contains infinitely many integers but is only of length $1$, which is absurd.
So we've found a point of non-continuity of $f$.