Question: how to train a cat to not pee on carpet?
Answer: Make Sure It's Not a Medical Problem. First, make sure it's not a medical problem. ... 
Make the litter box a “happy place.” Provide your cat with a brand-new litter box and fill it with fresh litter. ... 
Eliminate scent marking left by other cats.