I'm writing some PHP software to calculate prices. I'm having trouble wrapping my head around something. I'll put it in terms of cars to simplify what I'm looking for.

Average Cost of Car: $1000
Fee to Buy Car: 10%

Cost To Sell Car: 15%
Profit Needed: 25%

The software I'm building suggests prices to buy cars at based on the average sale price of the car. Here is how it works,

Car dealer buys car, pays extra 10% in a fee to buy
Car dealer pays 15% to 3rd party to market car
Car dealer wants to make at least 25% on the car.

I need to come up with some sort of equation of what to buy the car (before the buy fee) at knowing they are going to charge me an extra 10% to buy the car and then sell the car at the average market price minus the 15% fee it will cost me to sell the car. On top of it the price we pay for the car must leave 25% profit to be made. This gets tricky as the price we pay directly influences the buy fee. Of course what we buy the car for will be well below the average sell price of $1000 as we want to make money. Also keep in mind that we will assume we are going to be able to sell the car for $1000 not more or less.

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

If my previous question is answered "The 15% fee is based on the 3rd party selling price" the answer is this: (Buy cost) * 1.58125 = (sell price from 3rd party).

Thibault St john Cholmondeley-ffeatherstonehaugh the 2ndCommented:

I have you buying at 594
Add 10% gives 654
Add 15% gives 751
And sale price of 1000 allowing 249 to take as profit.
All other values were outgoing costs totalling 751. So you are taking about 25% of the sale price. If you want 25% of the cost then buy at 632.

Thibault St john Cholmondeley-ffeatherstonehaugh the 2ndCommented:

I actually used goal seek in excel but the calculation is as I showed. You could simplify this easily by using the result which is 1000 so you buy at 59.4% of your final sale price. If you want the full calculation just multiply the percentages so it's 1.10 x 1.15 x 1.33 The 1.33 is because you are taking .33 for profit and leaving 3x.33 as the costs so you are taking 25% of the sale.

Thibault St john Cholmondeley-ffeatherstonehaugh the 2ndCommented:

I missed a bit. If you multiply out those percentages you get 1.68245 which represents the total increase on the buy price. Get the inverse of this to find the buy price from the sale price. So 1/1.68245 which gives .594.
I hope that's clear enough.

Thibault St john Cholmondeley-ffeatherstonehaugh the 2ndCommented:

You are multiplying .1 .15 and .33.

It should be 1.1 1.15 and 1.33
You want to find the whole 110% etc of the price, not just the 10% figure.
It's the same as finding the price plus 10% of the price but shorter .

Thibault St john Cholmondeley-ffeatherstonehaugh the 2ndCommented:

You are losing me a bit now.
You started by saying you wanted a final sale price of 1000.
You wanted to take 25% of that for profit. leaving 750.
It is the 750 that contains the 15% sale fee.

Once you have a calc with a sale price of 1000 generating a buy of 594 then try with different values.

Thibault St john Cholmondeley-ffeatherstonehaugh the 2ndCommented:

Sorry thats not clear.
Its the reverse of adding a percentage on.
So if you want 25% of the whole but you only know the value that is left afterwards the remaining value must be 75% of the full figure (1000)
75% divides neatly into 3 so divide you need 4/3 of that price to find the full value you want the 25% of.

Thibault St john Cholmondeley-ffeatherstonehaugh the 2ndCommented:

You are still missing the Whole values. You need( sellp x sellpercent + sellp) What you are doing is just taking the percentage and not including the whole. For instance say you want to know the cost price plus the 25% profit you take the price and add it to the cost x .25. Your sum is just cost x .25 which simply finds a quarter if the cost. What you should multiply by is 1.25 which will find the sale price, not just the markup.

Thibault St john Cholmondeley-ffeatherstonehaugh the 2ndCommented:

Your last code has me lost. what are you actually trying to do?

Initially you stated three percentages that needed to be removed from the final sale price of 1000 (no more no less) and wanted a way to calculate the initial price.
Now you seem to be trying to find the sale price and adding a further 25%.
Have your requirements changed?

We need to know the list price to buy at knowing once we buy at that price an additional 10% will be tacked on. Then when I go to sell at the average price of $1000 I will lose $150 off the top in a 15% sell fee. The list price we choose to buy at we will want to make 25% on once the sale is complete.

For instance if we buy at $100 list price it comes out to us buying it at $110 after the buy fee.
We need to replace the $100 with the highest number we can buy at and still make 25% after paying listprice + 10% of listprice and then listing at $1000 and subtracting 15% sell fee.

After selling at average price we take in: $850 (after 15% subtracted)
So now we have to figure out what listprice is so that

$850 - (list price + 10%) = -25% or a 25% profit after fees.

Thibault St john Cholmondeley-ffeatherstonehaugh the 2ndCommented:

I think i'm getting it now. The 15% is from the final sale price.
The 10% is added to the cost price.
And adding those two amounts to the cist price gives your total costs.
You wush to make 25% of this total cost as a profit.
If that is correct then the calc is slightly different as I was adding the 15% before the profit was taken out and assuming you wanted profit calculated on the final sale.
I'll come back with a new calc.

This gross looking code figures it out. It stops when it finds the correct value. Here is the last bit of output, the last output is the correct number.

Total Buy Price with 10%: 680.053
Cost Before Buy Fee: 618.22
Sell Payout: 850
Percent Profit: 1.24992279889%

Total Buy Price with 10%: 680.042
Cost Before Buy Fee: 618.21
Sell Payout: 850
Percent Profit: 1.2499430173%

Total Buy Price with 10%: 680.031
Cost Before Buy Fee: 618.2
Sell Payout: 850
Percent Profit: 1.24996323637%

Total Buy Price with 10%: 680.02
Cost Before Buy Fee: 618.19
Sell Payout: 850
Percent Profit: 1.2499834561%

Total Buy Price with 10%: 680.009
Cost Before Buy Fee: 618.18
Sell Payout: 850
Percent Profit: 1.25000367648%

Thibault St john Cholmondeley-ffeatherstonehaugh the 2ndCommented:

I have a result.
Buy at 481.82
Add 10% (48.18) giving 530.00
Sell at 1000 and pay your 15% fee if 150.
Your costs are now 680.00
You have 850 coming in so leaving 170 profit which is 25% of the 680 costs.

There is a formula if these figures work for you I'll post it.

Thibault St john Cholmondeley-ffeatherstonehaugh the 2ndCommented:

Did you follow my calculations?
I'm adding 10% to the actual cost price and calling that a cost.
The 15% of the funal sale never changes. The sale price is always 1000 so 15% is 150.
I am also calling this a cost (perhaps it shouldn't be?)
Adding the 150 and the 530 costs give 680 total cost.
25% of the 680 cost is 170 (Your profit)
170+680+150= 1000, the final sale price.
Is this what you wanted?

Thibault St john Cholmondeley-ffeatherstonehaugh the 2ndCommented:

Hmm, can I try that again.
This time I'm buying at 618.18
Add a fee of 10% or 61.82 so costs are now 680 (without the sale fee).
25% of 680 is 170 si take your profit.
680 + 170 gives 850.
Sell at 1000 and subtract 150 for the 15% sale fee.
It adds up for me :7)
Buy price with those figures=618.18

Avg Cost - 25% = Car Dealer Cost

This takes into account both 10% and 15% fees and leaves 25% profit.