If $G/Z(G)$ is cyclic, then $G$ is abelian

We have that $G/Z(G)$ is cyclic, and so there is an element $x\in G$ such that $G/Z(G)=\langle xZ(G)\rangle$, where $xZ(G)$ is the coset with representative $x$. Now let $g\in G$. We know that $gZ(G)=(xZ(G))^m$ for some $m$, and by definition $(xZ(G))^m=x^mZ(G)$. Now, in general, if $H\leq G$, we have by definition too that $aH=bH$ if and only if $b^{-1}a\in H$. In our case, we have that $gZ(G)=x^mZ(G)$, and this happens if and only if $(x^m)^{-1}g\in Z(G)$. There then exists a $z\in Z(G)$ such that $(x^{m})^{-1}g=z$, and so $g=x^mz$. The hint is then proved, and the rest is identical to the work you did.


The following is another way to show the hint:

We know that the left cosets of $Z(G)$ partition the group $G$. So for all $g\in G$ there exists $n\in N, \ z\in Z(G)$ such that $x^nz=g$, where $xZ(G)$ generates $G/Z(G)$.