Assignment: Find $a$ and $b$ such that a piecewise function is continuous I'm having trouble solving a problem given in an assignment:

If the following function $f(x)$ is continuous for all real numbers $x$, determine the values of $a$ and $b$.
$$
f(x)=\begin{cases}
a\sin(x)+b~~~~~x\le 0\\
x^2+a~~~~~~~~~~0<x\le 1\\
b\cos(2\pi x)+a~~~~~~1<x
\end{cases}
$$

I've found through guesswork that an $a$ and $b$ are 1 and 1, although I'm not sure how to prove this.
 A: Notice that regardless of which values we give to the constants $a$ and $b$, the three functions $f_1(x) = a\sin x + b$, $f_2(x) = x^2+a$, and $f_3(x) = b\cos(2\pi x) + a$ are all continuous, and so the only points at which $f(x)$ can be discontinuous are the points $x = 0$ and $x = 1$ (where $f$ changes from being equal to $f_1$ to $f_2$ and $f_2$ to $f_3$, respectively). So from the definition of continuity at a point, we need to choose $a$ and $b$ that make
$$
\lim_{x\to x_0^-}f(x) = f(x_0) = \lim_{x\to x_0^+} f(x)
$$
true at the points $x_0 = 0$ and $x_0 = 1$.
Do you see how to proceed from here? Try to use the definition of $f$ and the above equalities to create two equations in the unknowns $a$ and $b$. I'll sketch how to do it below at $x_0 = 0$ as a spoiler.

[Spoiler: Interpreting the above equations at $x_0 = 0$]
From the meaning of the above limits and the definition of $f$, you should show that we need to choose $a$ and $b$ to ensure $b = a\sin(0) + b = \lim_{x\to 0^-}f(x) = f(0) = \lim_{x\to 0^+}f(x) = 0^2 + a = a$ is true. (Now setup a similar equation at $x_0 = 1$.)

