I started by considering the continuous function $h(x)=f(x)-g(x)$ and wanted to show $h(x)=0$ for all $x$. To do this I supposed there exists an $a\in\mathbb R$ such that $h(a)=b\ne0$. Now since $h$ is continuous at $a$, there exists a $\delta>0$ such that if $|x-a|<\delta$, then $|h(x)-h(a)|=|h(x)-b|<\epsilon$. So $h(x)\ne0$ in $a-\delta<x<a+\delta$. Conversely, since $S$ is a dense subset of $\mathbb R$ we know there exists an $s\in(a-\delta,a+\delta)$. Thus $h=0$ in this interval which is a contradiction. Thus, $f=g$.
I think I am missing two holes in the above proof and would much appreciate some help.
- I wasn't sure how to use the $\delta-\epsilon$ step to then get that $h(x)\ne0$.
- Did I actually reach a contradiction? Do I only need to find a single element in that interval where $h=0$ to achieve a contradiction or do I have to show $h=0$ for all $x$?
As Feng Shao says in their comment, you get to choose the $\epsilon$. Since $h$ is continuous you know that for every $\epsilon$ there is a $\delta$ so ..., and you use that by choosing a tiny $\epsilon$ that helps prove what you want to, and you know there is a $\delta$ that works. And, again as Feng said, $|h(a)|/2$ will do the job.
The contradiction should eventually be that there is an $x\in S$ so $h(x)\neq0$. You will actually end up showing that $h$ is non zero on a whole interval, but you only need one point in $S$ to get the contradiction.