Evaluate $\int_0^\pi\frac{\sin\left(n+\frac{1}{2}\right)x}{\sin \frac{x}{2}}dx$ 
Evaluate $$
\int_0^\pi\frac{\sin\Big(n+\frac{1}{2}\Big)x}{\sin \frac{x}{2}}dx
$$

$$
\int_0^\pi\frac{\sin\Big(n+\frac{1}{2}\Big)x}{\sin \frac{x}{2}}dx=\int_0^\pi\frac{\sin\Big(nx+\frac{x}{2}\Big)}{\sin \frac{x}{2}}dx=\int_0^\pi\frac{\sin nx.\cos\frac{x}{2}+\cos nx.\sin\frac{x}{2}}{\sin\frac{x}{2}}dx\\
=\int_0^\pi\sin nx.\cot\frac{x}{2}.dx+\int_0^\pi\cos nx.dx\\
$$
I don't think it is leading anywhere, anyone could possibly help with how to approach this definite integral ?
Note: The solution given in my reference is $\pi$
 A: Note that
$$2\sin\frac x2\cos x = \sin\frac32x -\sin\frac12x$$
$$2\sin\frac x2\cos 2x = \sin\frac52x -\sin\frac32x$$
$$…$$
$$2\sin\frac x2\cos nx =\sin(n+\frac12)x -\sin(n-\frac12)x $$
Sum up both sides,
$$2\sin\frac x2 (\cos x + \cos 2x + … +\cos nx )= \sin(n+\frac12)x - \sin\frac x2 $$
Therefore, 
$$
\int_0^\pi\frac{\sin\left(n+\frac{1}{2}\right)x}{\sin \frac{x}{2}}dx$$
$$=2\int_0^{\pi}(\cos x + \cos 2x + … +\cos nx )dx+\int_0^{\pi}dx= \pi$$
where all the cosine integrals vanish.
A: Hint
What is 
$$\sum_{k=0}^n e^{ikx}$$
using the sum of a geometric sequence?
A: Thanks @mathcounterexamples.net and @tommy1996q for the hint,
$$
\sum_{k=-n}^nr^k=\frac{1}{r^n}+...+\frac{1}{r^2}+\frac{1}{r}+1+{r}+{r^2}+...+r^n=r^{-n}.\frac{1-r^{2n+1}}{1-r}\\
$$
$$
\frac{\sin\Big(nx+\frac{x}{2}\Big)}{\sin \frac{x}{2}}=\frac{e^{i(nx+\frac{x}{2})}-e^{-i(nx+\frac{x}{2})}}{e^{ix/2}-e^{-ix/2}}=\frac{e^{-i(nx)}-e^{i(nx)}}{1-e^{ix}}\\
=e^{-i(nx)}\frac{1-e^{i(2nx)}}{1-e^{ix}}\\
a=e^{-inx},r=e^{ix}\\
=e^{-i(nx)}+e^{-i(nx)}.e^{ix}+e^{-i(nx)}.e^{2ix}+.........+e^{-i(nx)}.e^{(2n-1)ix}=\sum_{k=-n}^ne^{ikx}\\
$$
$$
\int_0^\pi\frac{\sin\Big(n+\frac{1}{2}\Big)x}{\sin \frac{x}{2}}dx=\int_0^\pi\sum_{k=-n}^ne^{ikx}dx\\
=\int_0^\pi \bigg[e^{-inx}+....+e^{-ix}+1+e^{ix}+e^{2ix}+....+e^{inx}\bigg]dx\\
=\int_0^\pi\bigg[\cos nx+\cos(n-1)x+\cos(n-2)x+...+\cos x\bigg]dx+\int_0^\pi xdx=\pi
$$
