What am I doing wrong with this CDF? All I'm trying to do is find the CDF of $f_{X+Y}(z)=\begin{cases}\frac z2 & 0\le z\le1\\ \frac12 & 1\le z\le2\\ \frac{(3-z)}{2} & 2\le z\le 3\\ 0 & \text{elsewhere} \end{cases}$
But I cant seem to figure it out. I know what the answers are but for whatever reason I cant get them. I thought to get them we simply do: $$\int_0^z\frac x2dx$$ Which I know is right, but then I go to the next one and tried a variety of different bounds and I couldn't get the right answer. So if someone could explain in general the process of finding CDF's and point out where I was going wrong that would be great. 

Let us call $Z=X+Y$. Then we aim at finding $F_Z(z)=P(Z\leq z)$. You have to deal with different values of $z$ seperately. For instance if $z<0$ we have
$$
P(Z\leq z)=\int_{-\infty}^z f_Z(x)\,\mathrm dx=\int_{-\infty}^z0\,\mathrm dx=0
$$
because $f_Z(x)=0$ when $x<0$. If instead $0\leq z\leq 1$, we have
$$
P(Z\leq z)=\int_{-\infty}^z f_Z(x)\,\mathrm dx=\int_{-\infty}^0 0\,\mathrm dx+\int_0^z\frac{x}{2}\,\mathrm dx,
$$
and if instead $1\leq z\leq 2$, then
$$
P(Z\leq z)=\int_{-\infty}^00\,\mathrm dx+\int_0^1\frac{x}{2}\,\mathrm dx+\int_1^z\frac{1}{2}\,\mathrm dx
$$
etc. I hope you see the pattern, otherwise leave a comment.
