The exact problem statement is,
Suppose that $f:\mathbb{R}\to\mathbb{R}$ and $g:\mathbb{R}\to\mathbb{R}$ are continuous on $\mathbb{R}$ and that $f(x)=g(x)$ for each $x\in U$ for some dense set $U\subset\mathbb{R}$. Prove that $f=g$ on all of $\mathbb{R}$.
My attempt at the proof is:
By way of contradiction, suppose the hypothesis and that there exists some $A\subset\mathbb{R}$ such that $f\neq g$ on $A$. Let us consider the function $f-g$, which is continuous on $\mathbb{R}$, since both $f$ and $g$ are continuous on $\mathbb{R}$. Notice that for each $a\in A$, $f(a)-g(a)\neq0$. Now, since $U$ is dense in $\mathbb{R}$, for each $x,y\in\mathbb{R}$ with $x<y$ there exists $u\in U$ such that $x<u<y$. Because $A\subset\mathbb{R}$, for each $a,b\in A$ with $a<b$ there exists $u\in U$ such that $a<u<b$, yet for every $u\in U$, $f(u)-g(u)=0$, implying $f-g$ is not continuous on $A\subset\mathbb{R}$, since $f-g\neq0$ on $A$.
I feel like I have the bulk of the proof down, but the last line I wrote doesn't sit right. Should I try to elaborate more or is that sufficient?
Is my approach even right or is there a simpler one?
Thanks for any help or feedback!
What you have doesn’t work as stated, because you’re using $u$ for many different things at once. Here’s a fairly simple argument that generalizes to other settings besides $\Bbb R$.
For something more along the lines that you had in mind, let $h=f-g$, and let $x\in\Bbb R$ be arbitrary. $U$ is dense in $\Bbb R$, so there is a sequence $\langle u_n:n\in\Bbb N\rangle$ in $U$ that converges to $x$. The function $h$ is continuous, so $\langle f(u_n):n\in\Bbb N\rangle=f(x)$. But $f(x_n)=0$ for each $n\in\Bbb N$, so $f(x)=0$.