We discuss the solutions of the Schroedinger equation for piecewise potentials, given by the harmonic oscillator potential for |x| > a and an arbitrary function for |x| < a, using elementary methods. The study of this problem sheds light on usual errors when discussing the asymptotic behavior of the eigenfunctions of the quantum harmonic oscillator and can also be used for the analysis of the eigenfunctions of the hydrogen atom. We present explicit results for the energy levels of a potential of this class, used to model the confinement of electrons in nanostructures.