solve $\sin x+\cos x=1$ 
How do we solve $\sin x+\cos x=1$?

I have solved it easily by making the substitution,
$\sin x+\cos x=1=R\sin(x+a)$ which gives the solutions $x=2n\pi, 2n\pi+\pi/2$. But when I do as follows
$$
(\sin x+\cos x)^2=1\implies 2\sin x\cos x=0\implies \sin 2x=0\implies2x=n\pi
$$
For even and odd
$$
2x=2m\pi\text{ or }2x=(2m+1)\pi\\x=m\pi\text{ or } x=m\pi+\frac{\pi}{2}
$$
What am I missing here ?

One way is this: if $\sin x + \cos x = 1$, then both $\sin x$ and $\cos x$ are non negative, otherwise the other one would be greater than $1$. If one of them is different from $0$ or $1$, one has
$$1 = \sin^2 x + \cos^2 x \lt \sin x + \cos x = 1$$
This is impossible. The only remaining possibilities are $(\sin x, \cos x) = (0, 1) $ or $(1, 0)$, hence $x = 2 k \pi$ or $\frac{\pi}{2} + 2 k \pi$.
