Things You'll Need
A clean cat box
There is no punishment that works for cats to stop them from peeing outside of the box. The best remedy is a clean litter box as well as a clean bill of health.
Cats that have been spayed or neutered are much less likely to urinate outside of the box. Spraying behavior usually goes away after the pet has been fixed. Sometimes females will urinate around the house before they go into heat. Getting them spayed eliminates this behavior. A clean and private area for your cat's litter box is the most appealing to felines. A black light can help you identify where the cat is peeing. Pet stores sell these lights now. If you're moving to a new home, get some Feliway and spray it around the new home to relax the cat and reduce their need to "mark" the house as their territory.
Punishing a cat for peeing on the carpet is a no-no. Cats do not pee outside of their litter boxes without a reason, and punishing them for doing so is confusing and harmful to the cat. The cat caretaker has to take steps to discover why the cat is peeing on the carpet, rug, or furniture in the first place, and then take action to mitigate the offending situations (for the cat, that is).
A cat that urinates outside of the litter box could have a physical disease. Cats develop urinary tract diseases occasionally, and they can be quickly fatal. Take your cat to the vet for a check up to make sure that the inappropriate urinating isn't health-related.
Some cats insist on having a squeaky clean litter box. You should make sure you take the dirty litter out each day. Start with a clean litter box and fresh litter as you put steps in place to curb the inappropriate behavior.
When you find the places where the cat has been urinating, use an enzyme spray to get rid of the smell. You can get these enzymes at pet stores or grocery stores. If the urine is on the carpeting, you may have to use the enzyme treatment several times to completely get rid of the odor.
Cover the area with aluminum foil and put a little vinegar in a small bowl on it. As creatures of habit, cats are prone to coming back to a place time after time, and they do not like the feel or sound of foil, and they hate the smell of vinegar.
If the clean litter is not enough to encourage your cat to use it, try switching types. Some cats have really sensitive feet and they may not like the disposable clay litter. Most cats like clumping litter because it is softer than other types.