Why doesn't integrating the area of the square give the volume of the cube?

Solution 1:

It should be:

$$V = \int_0^a a^2 dz$$

where $a$ is the length of one of the sides of the square.

Or using your notation:

$$V = \int_0^x x^2 dz$$

where $z$ is the dimension over which you are integrating.

Solution 2:

Actually, you have two errors there:

The minor one is that you seem to want a cube of side $2r$, since your integral goes from $-r$ to $r$.

The major error, as others have said, is that you are finding the volume of a pyramid, not a cube. Actually, since you are integrating from $-r$ to $r$, you are finding the volume of two pyramids, one upside-down, touching at their points. That is why you get $2r^3/3$, when the volume of one pyramid is $r^3/3$.