I belive that your value of $a_n$ is correct, and that the expression in problem (b) is incorrect. For your value of $a_n$, if $n=2m$ is even you get $a_{2m}=0$, and if $n=2m-1$ is odd you get $a_{2m-1}=-\frac{4}{\pi(2m-1)^2}$, giving the Fourier cosine series
$$ g(x) = \frac{\pi}{2}-\frac{1}{\pi}\sum_{n=1}^\infty\frac{4}{(2n-1)^2}\cos((2n-1)x).$$
If you instead would have had $a_n = \frac{2}{\pi n^2}((-1)^{n+1}-1)$, you would end up with the expression in (b), but this is incorrect.
First of all, am i right in thinking this function, because discontinuous, is neither odd or even.
No. Discontinuous functions can still be odd or even (or neither). For example, $f(x) = \begin{cases} 0, & -1 \le x \le 1 \\ 1, & x < -1 \\ -1, & x > 1 \end{cases}$ is odd and discontinuous.
However, the function you gave really is neither odd nor even.
In general, the best way to test a function $f(x)$ for oddness or evenness is to evaluate $f(-x)$. If you find that $f(-x) = -f(x)$, then $f$ is odd. If you find that $f(-x) = f(x)$, then $f$ is even. Or you can just look at the graph of $f$. If the graph of $f$ is symmetric over the $y$-axis, then $f$ is even. If the graph of $f$ is symmetric over the origin, then $f$ is odd.
Also, is my answer correct please:
The formulas for the coefficients of a Fourier series, if we integrate over $-L$ to $L$, are
\begin{align*}
a_n &= \frac1L \int_{-L}^L f(x) \cos \frac{n\pi x}L \, dx \quad (n=0,1,2,\dots)\\[0.3cm]
b_n &= \frac1L \int_{-L}^L f(x) \sin \frac{n\pi x}L \, dx \quad (n=1,2,3,\dots)\\[0.3cm]
\end{align*}
Note that this also requires we write the series as $$\frac{a_0}2 + \sum_{n=1}^{+\infty} \left(a_n \cos\frac{n\pi x}L + b_n\sin\frac{n\pi x}L\right)$$
In your case you have $L = \pi$, and you only need to integrate from $0$ to $L$ (i.e., $0$ to $\pi$) because your $f(x)$ is $0$ for $-\pi < x < 0$. So then:
$$a_0 = \frac1\pi \int_0^\pi \pi x \, dx = \frac{\pi^2}2$$
So that checks out.
$$a_n = \frac1\pi \int_0^\pi x \cos nx \, dx = \dots = \frac{(-1)^n-1}{n^2} $$
Looks like you're missing the $-1$ in the numerator on yours. Did you perhaps leave off a $\cos(nx)$ evaluated at $x=0$ when doing the integration?
$$b_n = \frac1\pi \int_0^\pi x \sin nx ,\ dx = \dots = \frac{\pi(-1)^{n+1}}n$$
Same as what you got in a slightly different form.
Let me know if you need more help fixing $a_n$.
Note: You can verify your answer by graphing on desmos.com. Here's a link for this one. I don't think desmos can handle infinite sums so I made the upper limit 100. High enough to get a clear picture.
Best Answer
By computing the Fourier coefficients in this manner, you've implicitly assumed that your function $f(x)$, which was defined on the interval $[0,2]$, has been periodically continued outside of that interval. But in that case, the behavior for $-1<x<0$ is $f(x)=1$ not $f(x)=x$. Hence the function is not odd.
To make this more visible, I've plotted your function along with its Fourier expansion (using modes $n=-10$ to $10$). The agreement is good near the center of the interval, but Gibbs phenomenon is evident near the edge.
$\hspace{4cm}$
Suppose we now look how the Fourier expansion behaves on the interval $[-2,4]$:
$\hspace{4cm}$
What we see is that the periodic continuation of the interval $[0,2]$ results in a sawtooth wave relative to the line $f(x)=1$. This clarifies the source of the Gibbs phenomenon, and makes clear that this function is neither even nor odd. Consequently we shouldn't be surprised that the $c_n$ are all in general complex.