Obviously, it should be titled: "Steak and Chicken Dinner Problem"

A wedding reception will have 200 guests and the dinner budget is \$9,000.

``````Wedding Catering Prices:
===================
Chicken Dinner: \$40
Steak Dinner: \$50``````

What is the highest number of steak dinners you can serve at this reception, and stay within the budget?

Let x = maximum number of steak dinners.

Now express the number of chicken digits, in terms of the number of the
number of steak dinners.

Cost per steak dinner * number of steak dinners + cost per chicken dinner(200 - x) = 9,000
=========================================================================

``````50x + 40(200-x) = 9,000
50x + 8000 -40x = 9,000
10x + 8000 = 9,000
10x = 1,000
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)``````

This would be done in just a few lines of code, using the above math. A short and sweet way to solve this kind of problem.

Just do the same math: In any case, guests * cost_of_chicken must be spent. The rest, that is budget - guests * cost_of_chicken may be used to pay an excess price of steak, that is price_of_stake - price_of_chicken.

steaks = (budget - guests * cost_of_chicken) / (price_of_stake - price_of_chicken)

## All 2 Replies

Just do the same math: In any case, guests * cost_of_chicken must be spent. The rest, that is budget - guests * cost_of_chicken may be used to pay an excess price of steak, that is price_of_stake - price_of_chicken.

steaks = (budget - guests * cost_of_chicken) / (price_of_stake - price_of_chicken)

Am I missing something?

This is a problem with two unknown but related, values. You can define either the number of chicken dinners in terms of the number of steak dinners, (as I did), or you can define the number of steak dinners in terms of the number of chicken dinners.

Either way, you can get the answers you need. ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.