#include <iostream>
int main()
{
int a,b,c,d,e,f,g,x;
for(x = 1; x <= 200; x++)
{
a = x * x * x;
for(e = 2; e < x; e++)
{
b = e * e * e;
for(f = e; f < x; f++)
{
c = f * f * f;
for(g = f; g < x; g++)
{
d = g * g * g;
if(a == ( b + c + d ))
std::cout << "Cube = " << x <<"," <<" "<< "Triple = "<<"("<< e << "," << f << "," << g <<")"<< std::endl;
}}}}
return 0;
}
My guess is that different combinations of the same permutation are being displayed. Check your code with their sample situation. If you change line 5 to for( x = 1; x <= 24; ++x) do you get the same output as them?
This comment is not very helpful, but it seems to me that all the on-line problems are not as trivial as they may first seem. They often involve clever ways of dealing with large numbers or culling lots of output to achieve the short execution times. They are very strict with the required output - 1 extra / missing char somewhere, and it fails - even though the data itself is correct.
So if you have come up with simple code as you have done, then there is probably more to it than you thought.
But good on you for giving it a go - these things are often quite challenging, and you will be a better programmer if you stick with it.
I tried out your program, and it worked great. I then changed variables a, b,c and d, from an int to double when I used a = pow(x,3), since I got the warning,
1>Perfect Cubes.cpp(11): warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data