0

Hello All,

Here are the instructions for the program I am trying to write:

Write a program that determines which 2, 3, and 4 digit #'s are equal to the sum of the cubes of their digits.

Ex.

if the original # is 234, determine if (2 cubed) + (3 cubed) + (4 cubed) is equal to 234.

The range of #'s is from 10 to 9999. I have gotten a result for the 3 digit #'s but not the 2 or 4. Please let me know if I am missing something or anyone has any suggestions

Thanks

```
int num, num1, num2, num3, dig1, dig2, dig3, dig4, sum;
cout <<"Section two results:" << endl;
print <<"Section two results:" << endl;
while (num <= 9999)
{
dig4 = num % 10;
num2 = num / 10;
dig3 = num2 % 10;
num3 = num2 / 10;
dig2 = num3 % 10;
dig1 = num3 / 10;
sum = (dig1 *dig1 * dig1) + (dig2 * dig2 * dig2) + (dig3 * dig3 * dig3)
<< + (dig4 * dig4 * dig4);
if (sum == num)
{
cout << " " << sum << endl;
print << " " << sum << endl;
}//end if
num++;
}//end while
num = 100;
while (num <= 999)
{
dig3 = num % 10;
num2 = num / 10;
dig2 = num2 % 10;
dig1 = num2 / 10;
sum = (dig1 * dig1 * dig1) + (dig2 * dig2 * dig2) + (dig3 * dig3 * dig3);
if (sum == num)
{
cout << " " << sum << endl;
print << " " << sum << endl;
}//end if
num++;
}//end while
cout << endl << endl;
num = 10;
while (num <= 99)
{
dig2 = num % 10;
dig1 = num / 10;
sum = (dig1 * dig1 * dig1) + (dig2 * dig2 * dig2);
if (sum == num)
{
cout << " " << sum << endl;
print << " " << sum << endl;
}//end if
num++;
}//end while
frz;
return 0;
```

*Edited 3 Years Ago by happygeek*: fixed formatting