The condition of the floor is one of the most important factors buyers consider when shopping for a new house. Buyers would prefer to pay a little extra for a clean floor that will last them a long time. By all means, do a thorough job cleaning your floor first but if it is worn, stained, ripped or buckled, you should replace it.
Yes, it will cost you thousands of dollars but your house will look spectacular. This should translate into a higher selling price thus recouping the cost of the new carpet. Do not make a price concession because your floor is in poor condition. It is much cheaper to replace your own carpet and flooring.
Make sure you select a color that will appeal to the broadest segment of buyers. Beige is the safest color since it will go well with most decors and furniture.