Let $f(x) = \begin{cases} x^3cos^2(\frac{1}{x}) & \text{x is irrational} \\ a & \text{x is rational}\end{cases}$ where $a$ is a constant.
If $a \neq 0$, prove that $f$ is not continuous at $x=0$.
I approached this question as follows:
$$0 \leq cos^2 (\frac{1}{x}) \leq 1 \Rightarrow 0 \leq cos^2(\frac{1}{x}) \leq x^2$$ and since $\lim\limits_{x \to 0}0 = 0$ and $\lim\limits_{x \to 0} x^2 = 0$, by the Squeeze Theorem, $\lim\limits_{x \to 0} x^2 cos^2 (\frac{1}{x}) = 0$. Consequently, $$\lim\limits_{x \to 0} x^3 cos^2 (\frac{1}{x}) = \lim\limits_{x \to 0} x \cdot \lim\limits_{x \to 0} x^2 cos^2 (\frac{1}{x}) = 0 \cdot 0 = 0$$However, $\lim\limits_{x \to 0} a = a \neq 0$, i.e.$\lim\limits_{x \to 0} a \neq \lim\limits_{x \to 0} x^3 cos^2 (\frac{1}{x})$, so the function $f$ does not approach a single value as $x \to 0$, i.e. $\lim\limits_{x \to 0}f(x)$ does not exist. Since we require $\lim\limits_{x \to 0}f(x) = f(0)$ to conclude continuity of the function at $x=0$, the function is not continuous at $x = 0$.
Is this line of reasoning correct? How could this question be tackled instead? Any help would be appreciated, thanks in advance!
By squeezing, $$\lim_{x\to0\\x\notin\mathbb Q}f(x)=0,$$
while $$f(0)=a,$$ and this is enough to conclude.