C++之水仙花数无法找出错误原因

水仙花数为什么无法得出?
!

img

https://img-mid.csdnimg.cn/release/static/image/mid/ask/328558672266130.png "#left")

Can you help me?
Thank you very much!

img

#include <iostream>

int cube(int x) { return x * x * x; }

int main()
{
    int n = 100;
    int a[3];
    do
    {
        int x = n;
        int i = 0;
        while (x)
        {
            a[i++] = x % 10;
            x /= 10;
        }
        if (cube(a[0]) + cube(a[1]) + cube(a[2]) == n)
            std::cout << n << '\n';
    } while (++n < 1000);
    return 0;
}