How the sample mean changes when you add a new observation I don't know how to solve in my statistics homework problem

Sample

In a class of 6 students, their average age is 21. When the teacher joins the class, the avg age becomes 26. What's the age of the teacher ?

Is there a formula to do this or a series of substitutions ?
If you have the sample average based on $n$ samples, $\overline{x}_n$, and add a new observation, $x$, then the new sample average is 

$$ \overline{x}_{n+1} = \frac{ n \overline{x}_n + x }{n + 1} $$

using the data you provided, $\overline{x}_n = 21$, $n = 6$ and $\overline{x}_{n+1} =  26$, so you know 3 out of 4 unknowns: 

$$ 26 = \frac{ 6 \cdot 21 + x }{6 + 1} $$

and you can solve for the last unknown, $x$, which I'll leave to you. I hope this helps!!
Given: $n_1=6,n_2=7$ $\text{Mean}_1=21\text{ Mean}_2=26$ Age of the Teacher$=(n2\times \text{ Mean}_2)-(n1\times \text{Mean}_1)$
Age of the Teacher$=(7\times 26)-(6\times 21)$
Age of the Teacher$=56$