I'm not understanding how to set up these equations in terms of profit, revenue, and cost.

I know P=R-C. That all seems sort of elementary, but when I impliment it I'm messing up somewhere as I'm getting different answers as to what is written in the back of the book.

Here is the problem given.

Maximum Profit: A commodity has a demand function modeled by $\displaystyle p=100-0.5x^2$ and a total cost function of $\displaystyle C=40x+37.5$

a.) What price yields a maximum profit?

b.) When the profit is maximized, what is the average cost per unit?

Here is how I'm attempting to work the material out

The equation should be set up in terms of Profit=Revenue-Cost and the maximum profit can be taken from the derivative of that equation.

So... revenue is $\displaystyle R=xp$ gained from units sold multiplied by the price and the cost equation was given above, so just plugging them in I set them up like this.

$\displaystyle P=x(100-0.5x^2)-40x+37.5$

into

$\displaystyle P=100x-0.5x^3-40x+37.5$

into

$\displaystyle P=-0.5x^3+60x+37.5$

working out the - and finding the first derivative this is where I went from here

$\displaystyle P'=1.5x^2-60$

which would become $\displaystyle \frac{60}{1.5}=x^2$

which is $\displaystyle 40=x^2$

The back of the book says I should have gotten $80 and I got$\displaystyle \sqrt40$. What did I do wrong and how do I go from there to find the average cost per unit when maximized? Thanks in advance