Using $p$ for prices, $q$ for quantities (amounts) the two formulae are
$${{\sum_i (p_{2i}/p_{1i}) q_{1i}} \over {\sum_i q_{1i}}}-1$$
and
$${{\sum_i p_{2i}q_{1i}} \over {\sum_i p_{1i}q_{1i}}}-1
={{\sum_i (p_{2i}/p_{1i}) p_{1i}q_{1i}} \over {\sum_i p_{1i}q_{1i}}}-1$$
So both are weighted average of price changes with the weights being the first-period quantities in the former and the first-period volumes in the latter. There is no right answer since only the user can decide which system of weights better captures the relative importance of commodities.
However there is one argument against the first formula. The quantities depend on the choice of units. If you start measuring one commodity in grams rather than kilograms then its importance in the index would go up thousandfold. This is not a problem in the second case.
The second formula also has the advantage of being well known. It is called the Laspeyres index. The problem you are trying to solve has plagued economists for long. So much so that cutting edge macroeconomic texts of the early twentieth century would devote full chapters to it.
Very large hint, without being a complete solution
Let $N$ denote the (unknown) number of students.
Let $S$ denote the (unknown) sum of their ages. Then the average age of the students is
$$
u = S/N.
$$
If we add Dan to the class, how many students, $N'$, will there be? And what will the sum, $S'$ of their ages be, in terms of $S$? And what does that make the average age $u'$ of this enlarged class in terms of $N$ and $S$? Once you know that, and set
$$
u' = u - 10,
$$
and then replace $u$ and $u'$ by the formulas for them, you get one equation in the two unknowns $N$ and $S$.
If we now add Michael to the class, we get yet another number, $N''$ of students, and yet another age-sum, $S''$. How are these related to $N'$ and $S'$ (or to $N$ and $S$)? We also get yet another average age, $u''$, and know know that
$$
u'' = u' - 8
$$
That gives us a second equation in the unknowns $N$ and $S$. Perhaps you can take it from here.
(Suggestion: Carry out the ideas I've described here and edit your question --- click on the word "edit" below the question to do so --- and show what you've gotten; perhaps we can then help your further if you still need it.)
Post-comment addition
You've got
\begin{align}
10 &= \frac{S}{N}-\frac{S+16}{N+1}\\
18 &=\frac{S}{N}-\frac{S+28}{N+2}
\end{align}
and that's great. It's typical, in situations like this, to clear the denominators, i.e., to multiply through by $N$ and $N+1$ or $N + 2$, resulting in
\begin{align}
10N(N+1) &= S(N+1)-(S+16)N\\
18N(N+2) &=S(N+2)-(S+28)N
\end{align}
When you expand out the right hand sides, a funny thing happens here: there are several $SN$ terms, and they all cancel. So you get
\begin{align}
10N(N+1) &= S-16N\\
18N(N+2) &= 2S-28N
\end{align}
From the first equation, we can solve for $S$; we can then plug this into the second equation to get an equation involving only $N$. That's good...we might be able to solve it. But it's a quadratic...that's potentially bad, because maybe there'll be two equally valid solutions. Or maybe they won't be equally valid. Why don't you go ahead and see where you end up when you follow that plan?
Best Answer
The properties of flooring allow us to simplify the expression to $$ \left\lfloor \frac{ x + N/x}{2}\right\rfloor $$ We can also tell that the value will change between $x$ and $x + 1$ if there is a real number $y$, $x < y < x+1$ such that $(y + N/y)/2$ is an integer. Calling this integer $k$, we can set $k = (y + N/y) /2$ and solve for $y$ to get $$ x = \lfloor y \rfloor = \lfloor k \pm \sqrt{k^2 - N}\rfloor $$ Applying this formula to the values $[678, 683]$ gives $615, 606, 598, 591, 585, 579$, which lines up perfectly with the spreadsheet.