For a price-taking firm every extra pack sells for the market price, so marginal revenue is a horizontal line at $4. Marginal cost, the extra cost of ten more packs divided by ten, falls at first over the region of increasing marginal returns and then rises as diminishing returns set in. Each dot is one row of the table; the curve joins them.
Where marginal revenue is above marginal cost, at 40 or 50 packs, one more pack adds more revenue than cost and profit rises. Where marginal cost is above marginal revenue, at 90 or 100 packs, cutting back raises profit. The profit-maximizing output is where MR = MC, 80 packs at a price of $4. The slider changes the price and the crossing moves along the marginal cost curve.