We consider, in discrete time, a single machine system that operates for a period of time represented by a general distribution. This machine is subject to failures during operations and the occurrence of these failures depends on how many times the machine has previously failed. Some failures are repairable and the repair times may or may not depend on the number of times the machine was previously repaired. Repair times also have a general distribution. The operating times of the machine depend on how many times it has failed and was subjected to repairs. Secondly, when the machine experiences a nonrepairable failure, it is replaced by another machine. The replacement machine may be new or a refurbished one. After the Nth failure, the machine is automatically replaced with a new one. We present a detailed analysis of special cases of this system, and we obtain the stationary distribution of the system and the optimal time for replacing the machine with a new one.