The Erdős–Ginzburg–Ziv theorem for dihedral groups