Finding a space $X$ such that $\dim C(X)=n$.
This is possible only for $n=0$. In fact, the following stronger statement is true.
Let $X$ be a nonempty topological space. Then $C(X)$ is $0$-dimensional if every $f\in C(X)$ is locally constant, and otherwise $C(X)$ is infinite-dimensional.
To prove this, first suppose that every $f\in C(X)$ is locally constant. Then for any $f\in C(X)$, the function $g$ defined by $g(x)=1/f(x)$ if $f(x)\neq 0$ and $g(x)=0$ if $f(x)=0$ is continuous. Since $fgf=f$, this proves $C(X)$ is von Neumann regular (and not the zero ring since $X$ is nonempty) and thus $0$-dimensional.
Now suppose some $f_0\in C(X)$ is not locally constant. Say $x_0\in C(X)$ is such that $f_0$ is not constant in any neighborhood of $x_0$. By subtracting a constant from $f_0$, we may assume $f_0(x_0)=0$.
Since $f_0$ does not vanish identically in any neighborhood of $x_0$, $x_0$ is in the closure of the set $A=f_0^{-1}(\mathbb{R}\setminus\{0\})$. Let $U$ be some ultrafilter on $A$ which converges to $x_0$. For each $k\in\mathbb{N}$, define $$P_k=\{f\in C(X):\lim_Ue^{a|f_0(x)|^{-k}}f(x)=0\text{ for all }a\in\mathbb{R}\}$$ where $\lim\limits_U$ denotes the limit with respect to $x$ along the ultrafilter $U$. Intuitively, you can think of $P_k$ as consisting of those functions which go to $0$ along $U$ "much faster" than $e^{-|f_0|^{-k}}$. I claim that for any $k$, $P_k$ is a prime ideal.
First, $P_k$ is clearly closed under addition. Since any continuous function on $X$ is bounded in a neighborhood of $x_0$ and $U$ converges to $x_0$, $P_k$ is closed under multiplication by arbitrary elements of $C(X)$. To show $P_k$ is prime, suppose $g,h\not\in P_k$. Then for some $a\in\mathbb{R}$ and some $\epsilon>0$, the set $$S=\{x\in A: |e^{a|f_0(x)|^{-k}}g(x)|>\epsilon\}$$ is in $U$ (here we use the fact that $U$ is an ultrafilter; if $U$ were just a filter all we would know is that the complement of some such set $S$ is not in $U$). Similarly, for some $b\in\mathbb{R}$ and some $\epsilon'>0$, the set $$T=\{x\in A: |e^{b|f_0(x)|^{-k}}h(x)|>\epsilon'\}$$ is in $U$. Since $U$ is a filter, $S\cap T\in U$ as well. But if $x\in S\cap T$, then $$|e^{(a+b)|f_0(x)|^{-k}}g(x)h(x)|>\epsilon\epsilon'.$$ This witnesses that $gh\not\in P_k$.
So each $P_k$ is a prime ideal, and it is clear that if $k\leq \ell$ then $P_\ell\subseteq P_k$. To conclude that we have an infinite chain of prime ideals and so $C(X)$ is infinite-dimensional, we thus only need to show that $P_k\neq P_{k+1}$ for each $k$. To prove this, just consider the function $f(x)=e^{-|f_0(x)|^{-k-1}}$ (with $f(x)=0$ when $f_0(x)=0$). Note that $f_0(x)$ converges to $0$ along $U$ and so $e^{a|f_0(x)|^{-k}-|f_0(x)|^{-k-1}}$ converges to $0$ along $U$ for any $a$. Thus $f\in P_k$. But $f\not\in P_{k+1}$, since $e^{a|f_0(x)|^{-k-1}-|f_0(x)|^{-k-1}}$ goes to $\infty$ as $f_0(x)$ approaches $0$ for $a>1$. Thus $P_{k+1}\neq P_k$.
(Actually, we don't need to restrict to $k\in\mathbb{N}$; we could let $k\in[0,\infty)$ and a similar argument would still work. So we actually get a chain of primes indexed by $[0,\infty)$, not just a countable chain.)