I believe it's called "using weighted variables", in arithmetic. I've seen the "simple" equation for it, but it's VERY unintuitive, to my mind. I greatly prefer the algebraic format of the problem:
In this example, not the different budget value.
Code:
Let x = number of steak dinners possible
Express chicken dinners in terms of the streak dinners:
50x + 40(200-x) = 9,000
Distribute the 40 across the quantity (200-x)
50x + 8000 -40x = 9,000
Combine the x terms:
10x + 8000 = 9,000
Subtract the 8,000 from both sides of the equation:
10x = 1,000
And divide by 10:
x = 100
steak dinners = 100
chicken dinners = 100
100 * 50 = 5,000
100 * 40 = 4,000
================
200 $9,000
Could we squeeze in just one more steak dinner?
101 * 50 = 5050
99 * 40 = 3960
===============
200 $9,010 (nope, over budget)
I used code tags for the above because it won't line up otherwise.
So your code would use logic like:
math equals =, not assignment:
stkcost * stkdinners + chkcost (guests - stkdinners) = budget
chkcost * guests = minimum possible to spend (all chicken dinners) //getting there
900 - (chkcost * guests) = amount left for steak dinner expense
stkcost - chkcost = extra expense per dinner for steak
Here's your code equation:
stkdinners = (budget - chkcost(guests))/(stkcost-chkcost)
maximum steak dinners, while still meeting budget restraint
chkdinners = guests - stkdinners
Give that a shot.