People with multiple sclerosis have a nearly fivefold increased risk of developing dementia compared with those without MS, a study found.