Figuring out the cause and being able to take care of it may not be the same. This cough most likely is the result of a viral infection. It can follow the exact course you have described. The cough itself or the virus may have inflamed the nerves in your chest wall causing the pain. However, an infection of the lining of the lung can also cause severe pain. You can start with simple anti-inflammatory medications. However, if this does not work and/or the cough is persisting, a physician visit is definitely your best next step.