The crux of the matter is how n
is changed on each iteration.
Math
Consider a multi-digit integer $n = a_1 a_2 a_3 \ldots a_N$, where $a_k$ is the $k$-th digit of $n$ in base $10$, and $a_1 \neq 0$.
Then, since $a_1 a_2 \ldots a_N = \left( a_1 a_2 \ldots a_{N-1} \right)10 + a_N$,
\begin{equation}
\text{ mod}(n, 10) = \text{ mod}(a_1 a_2 \ldots a_N, 10) = a_N
\end{equation}
Therefore $n - \mathrm{mod}(n,10) = \left( a_1 a_2 \ldots a_{N-1} \right)10 \ $ and thus
\begin{equation}
\dfrac{n - \mathrm{mod}(n,10)}{10} = \dfrac{\left( a_1 a_2 \ldots a_{N-1} \right)10}{10} = a_1 a_2 \ldots a_{N-1}
\end{equation}
Then nest $N-1$ more times.
Then, since $\mathrm{mod}(j,10) = j$ for $j \in \{\mathbb{Z} : 0 \leq j < 10\}$ and $a_1 \in \{\mathbb{Z} : 0 < a_1 < 10\}$ by the definition of a digit in decimal expansion and our restriction, the last re-assignment of $n$ is just
\begin{equation}
n = \dfrac{a_1 - \mathrm{mod}(a_1,10)}{10} = \dfrac{a_1 - a_1}{10} = 0
\end{equation}
which breaks on next test of $n > 0$.
So, the appropriate change of $n$ on each iteration is $\boxed{n = \dfrac{n - \mathrm{mod}(n,10)}{10}}$.
Code
Block[
{n = Input["Enter a multi-digit number"], sum = 0},
While[n > 0, sum = sum + Mod[n, 10]; n = (n - Mod[n, 10])/10];
StringForm["The square of the sum of the digits is: ``", (sum)^2]
]
Block[
{n = #, sum = 0},
While[n > 0, sum = sum + Mod[n, 10]; n = (n - Mod[n, 10])/10];
StringForm["The square of the sum of the digits is: ``", (sum)^2]
] & /@ {11, 12, 21, 111}//Column
The square of the sum of the digits is: 4
The square of the sum of the digits is: 9
The square of the sum of the digits is: 9
The square of the sum of the digits is: 9
Another Method
If, in the case that you don't need to use a While
loop, you can use the built in RealDigits
(or IntegerDigits
if n
is always an integer) to get a list of the digits of any real number.
Total[First@RealDigits@Input["Enter a multi-digit number"]]^2
Total[First@RealDigits@#]^2 & /@ {11, 11., 11.1}
{4, 4, 9}
While
loop? $\endgroup$