Linear Differential Equation but with piece wise function ( Cant Solve ) Find a continuous solution satisfying the DE
$$y' + y = f(x),$$
where 
\begin{align}
f(x) &= \begin{cases}
1, &  0 \leq x \leq 1 \\
-1, &  x>1\text{.}\end{cases}\\
y(0)&=1\end{align}
I am new to the forum so sorry guys for the format mistakes but really looking for the solution of this desperately & the 2nd question is
$$y' + 2xy = f(x),$$ 
where
\begin{align}
f(x) &= \begin{cases}
x, &  0 \leq x \leq 3 \\
0, &  x >1\text{.}\end{cases}\\
y(0)&=2\end{align}
These questions are in my Book ODE by Zillls 3rd Edition Exercise 2.5 . Question number 57,58
Kindly help me out mates , i will be thankfull 

First equation
(Update Fixed, thanks to RodrigodeAzevedo)
Consider $0 \leq x \leq 1$, then:
$$\begin{cases}
y' + y = 1 \\
y(0) = 1
\end{cases} \Rightarrow y(x) = 1 \Rightarrow y(1) = 1.$$
Now, solve the differential equation for $x > 1$:
$$\begin{cases}
y' + y = -1 \\
y(1) = 1
\end{cases} \Rightarrow y(t) = 2e^{-x+1} - 1.$$
Finally:
$$y(x) = \begin{cases}1 & 0 \leq x \leq 1 \\
2e^{-x+1} - 1 & x > 1.
\end{cases}$$
Notice that for $x=1$, this function is continuous.
Second equation
This can be solved by using the very standard method of Separation of variables.
Consider $0 \leq x \leq 3$, then:
$$\begin{cases}
y' + 2xy = x \\
y(0) = 2
\end{cases} \Rightarrow \\
\frac{dy}{dx} = x(1-2y) \Rightarrow \\
\int_{y(0)}^{y(x)}\frac{dy}{1-2y} = \int_0^x s ds \Rightarrow \\
\int_{2}^{y(x)}\frac{dy}{1-2y} = \int_0^x s ds \Rightarrow \\
-\frac{1}{2}\left[\log\left(y(x)-\frac{1}{2}\right) - \log\left(\frac{3}{2}\right)\right] = \frac{1}{2}x^2 \Rightarrow \\
y(x) = \frac{3e^{-x^2}+1}{2} \Rightarrow 
y(3) = \frac{3e^{-9}+1}{2}.$$
Now consider $x > 3$, then:
$$\begin{cases}
y' + 2xy = 0 \\
y(3) = \frac{3e^{-9}+1}{2}
\end{cases} \Rightarrow \\
\frac{dy}{dx} = -2xy \Rightarrow \\
\int_{y(3)}^{y(x)}\frac{dy}{y} = -2\int_0^x s ds \Rightarrow \\
\int_{\frac{3e^{-9}+1}{2}}^{y(x)}\frac{dy}{y} = -2\int_3^x s ds \Rightarrow \\
\log\left(y(x)\right) - \log\left(\frac{3e^{-9}+1}{2}\right) = -(x^2-9) \Rightarrow \\
y(x) = \frac{3e^{-9}+1}{2}e^{-(x^2-9)}$$
Again, this is continuous for $x=3$.
