It’s best not to punish the puppy for making a mistake. Instead, focus on praising appropriate bathroom behavior. If you catch your puppy in the act, interrupt it by saying “No!” in a firm voice or clapping your hands loudly, then take the puppy outside to finish going to the bathroom. Never swat your puppy, yell at it, or try to rub its nose in the mess.
Young puppies can’t hold their bowels & bladders for long. If you come home to find that they’ve had an accident in there it’s quite possible that they can’t hold it that long. Generally puppies can hold their bladder for about one hour per month of age. So your 3 month old pup can probably only hold their bladder for about 3 hours. If you’re going to be away at work for long periods of time see if you can get a neighbor, relative or dog sitter to come over to let your pup out during the day.
Just because your new dog is old enough that he should know where to potty doesn’t mean that he actually does. An adult dog has the necessary muscle control to hold it for longer periods of time, but if no one ever taught him the potty training rules then he’s the equivalent of a brand new puppy. Age should not be equated with housetraining prowess, so it’s a good idea to treat any dog new to your home as if he’s still learning the potty training ropes.
Be persistent! Make sure the puppy doesn't get the opportunity to pee and poop by using a leash indoors or confining him to a crate when you're out. Depending on the puppies age, pop him outside every 20 - 30 minutes, so there's a greater chance of him toileting outside (by accident at first.) In addition, get rid of any scent markers he's left by peeing or pooping indoors, as these will draw him back to the same spot. This means cleaning the area daily, for 2- 3 weeks after he last pooped there to fully get rid of any lingering odor that the dog can detect.
The process is the exactly same for older dogs as it is for puppies; prevent accidents from happening by using baby gates and a crate if possible, create a predictable schedule, learn to recognize your dog’s potty signals, accompany your dog outside and immediately reward for all outdoor elimination, properly clean any accidents and supervise your dog until you’re sure that he understands the rules.