Sandwich rule for continuity Let $c ∈ X ⊆ R $ . Suppose that $f : X → \mathbb{R}$, $g : X → \mathbb{R}$, and $h : X → \mathbb{R}$ are functions such that $g(x) ≤ f(x) ≤ h(x)$ for all $x ∈ X$.
Suppose that $g$ and $h$ is continuous at $c$ and $g(c) = h(c).$
Question: Show that f is continuous at c.
Attempt:
I have started by writing down the following.
Let $\epsilon >0$. We know that $g$ is continuous hence we have $\delta_g$ such that
$|x-c|< \delta_g$ $\implies$ $|g(x)-g(c)|< \epsilon$.
We know that $h$ is continuous hence we have $\delta_h$ such that
$|x-c|< \delta_h$ $\implies$ $|h(x)-h(c)|< \epsilon$.
How do I connect $f$ to $h$ and $g$?
 A: Presumably, the sandwich theorem for limits is allowed. So by this theorem,
$$\lim_{x\to c}g(x)\le\lim_{x\to c}f(x)\le\lim_{x\to c}h(x).$$
In addition, by continuity of $g$ and $h$,
$$\lim_{x\to c}g(x)=g(c),\\\lim_{x\to c}h(x)=h(c).$$
Hence
$$\lim_{x\to c}f(x)=f(c)=g(c)=h(c)$$ QED.

Note that continuity of $g$ and $h$ is required, otherwise you could very well have
$$\lim_{x\to c}g(x)\ne g(c)\text{ and }\lim_{x\to c}h(x)\ne h(c).$$
A: First note that setting $x=c$ in the inequality implies that $g(c) \le f(c) \le h(c) = g(c)$ and therefore $g(c) = f(c) = h(c)$.
For $\epsilon > 0$ you have found $\delta_g > 0$ and $\delta_h > 0$ such that
$$
|x-c|< \delta_g \implies |g(x)-g(c)| < \epsilon \implies g(x) > g(c) - \epsilon\\
|x-c|< \delta_h \implies  |h(x)-h(c)| < \epsilon \implies h(x) < h(c) + \epsilon
$$
Now set $\delta = \min(\delta_g, \delta_h)$. Then $|x-c| < \delta$ implies
$$
 f(c) - \epsilon = g(c) - \epsilon <  g(x) \le f(x)
$$
and
$$
 f(x) \le h(x) < h(c) + \epsilon =  f(c) + \epsilon 
$$
and therefore
$$
 f(c) - \epsilon < f(x) <  f(c) + \epsilon \iff |f(x) - f(c)| < \epsilon \, .
$$
