There is an excellent spray called "Keep Off" (I used to buy it online-- about $10) -- that you can spray on the carpet, or spray it on something like a sheet of plastic (painter's plastic sheet) and put over the carpet. Best thing to do is get a really good pet deoderizer on the carpet first (Urine B Gone works great for both urine and fecal stains and odors), then after drying, lightly moisturize the carpet with the Keep Off. Dogs don't like the smell of it. Can you close the door to this room to keep the dog out while you're doing this?
Well if the areas weren't cleaned properly with a cleaner that has enzymes to break down the odor in the pee and pooh then each spot to the dog just says pee and pooh here to remark your territory. Proper cleaning is very important then you need to train the dog.