A more logical approach to a word problem I was taught in high school algebra to translate word problems into algebraic expressions. So when I encountered this problem I tried to reason out an algebra formula for it

For every dollar Ben spent on bagels, David spent 25 cents less. Ben
paid $12.50 more than David. How much did they spend in the bagel store
together?

To solve this I imagined a series of comparisons when Ben spends $x$, David spends $.75x$. Loop this relationship until $x - .75x \approx 12.50$. Good. Done. $x = 50$, then add David's for the answer. Coming from computers, I would have set this up in code where a loop (recursion) would increase $x$ until the condition $x - .75x = 12.50$ was met, then the "loop counter/accumulator" would be how much Ben spent, i.e., $50$, etc.
I'm a beginner with math, but it seems like there should be a better approach, something with series and sequences or even calculus derivatives, something better than my brute-force computer algorithm. Can someone enlighten? The "answer" given at the site (see link) is its own brute-force and hardly satisfying. I'm thinking there should be something more formal -- at least for the first part that derives $50$.
Update
I think everyone so far has missed my point. Many of you simply re-did the problem again. I'm wondering if there is a more formal way to do this other than just "figuring it out" (FIO). The whole FIO routine is murky. It looks like a limit problem; it looks like a system of equations, but I'm not experienced enough to know exactly. If there isn't, then let's call it a day....
 A: From the step $x-.75x=12.50$ simplify to $.25x=12.5$,  divide by .25  to immediately get $x=50$.  No looping/brute force needed.
A: Another way, with no $x$'s needed:
The first condition says the difference between their spending is $1/4$ of what Ben spends.  That difference is $\$12.50$, so Ben's amount is $4 \times \$ 12.50 = \$50$.
A: If the difference is $\$12.50$ then it must be the product of dollars times $\$0.25$ so we divide:
$\quad\dfrac{12.50}{0.25}=50\quad$ for Ben and another $\quad 37.50 \quad$ for David for a total of $\quad\$87.50$
A: You can use linear algebra, by defining something as x, say the amount paid by Ben. Then Dave's will be 0.75x. Then we can get an easily solvable equation.
A: I have to admit I'm having a hard time seeing how you "imagine a series of comparisons " and how you "loop" them.
As a mathematician, I simply view this as Ben did a single transaction where in one go he spent $x$ dollars on bagels.
Therefore David spend $0.75x$ on bagels (in one go).
Set one equation (no series of loops) to get $x - 0.75x = 12.50$ and solve:

$x-0.75x = 12.50$
$0.25x = 12.50$
$\frac {0.25}{0.25} x = \frac {12.50}{0.25}$
$x = 50$

So Ben spent $50$ dollars on bagels.
Now add Davids answer.  David spent $0.75x$ and $x = 50$ so David spent $0.75 \times 50 = 37.50$.  Adding that they added $50+37.50 = 87.50$.
Or.... Ben spent $x$ and David spent $0.75x$ so together they spent $x + 0.75x = 1.75x$ and as $x = 50$ together they spent $1.75\times 50 = 87.50$.
