The question is as follows. Let $(X,d)$ be a compact metric space, and let $f:X \rightarrow \mathbb R $. Assuming that for each $r \in \mathbb R$, the set $G_r=\{x \in X : f(x) \lt r\}$ is open, prove that f is bounded above.
My attempt: I've assumed that $\{G_r\}$ is an open cover of $X$. Since $X$ is compact $\{G_r\}$ contains a finite subcover such that $X \subset G_{r_1} \cup \cdots \cup G_{r_n}$. Finally we take $r=max\{r_1, \cdots,r_n\}$ and for all $x\in X$, $f(x) \lt r$.
I am not convinced that $\{G_r\}$ forms a open cover of $X$, which makes me doubt that my proof is incorrect. Is my proof valid and if so why does $\{G_r\}$ forms a open cover of $X$?
Assume that $\{ G_r \}_{r \in \mathbb{R}}$ is not an open cover of $X$, then there exists $x \in X$ such that $f(x) > r$ for all $r \in \mathbb{R}$ i.e. $f(x) = \infty$. But, we can't have a point $x$ that takes infinite value, since the range is the reals.