Help with volume of cross-sections please!

Straight from my book:

"The base of a solid is the region in the xy-plane bounded by Y = Sinx, the X-axis, X = 0, and X = pi/2. What is the volume of the object if every vertical slice of the object parallel to the X-axis is a square?"

Setting up the integral gives us -

{(0,1) (pi/2 - X)^2 dy

I thought I could easily solve the integral but I was wrong. You see, all the variables in the integral must be the same type. So either it's in terms of Y and dy or X and dx. I tried doing it in terms of Y and dy but it was just impractical (I had to find the integral of several "arctan y" squared, pfft). I was shocked, I knew no way of solving the integral. So I thought I'd just change the integral to the variable of dx even though I knew it to be wrong. All I did was exchanging dy with dx and changing from (0,1) to (0, pi/2). But it didn't work since the book gave me different answer. My book reformed the integral as the following -

{(0, pi/2) (pi/2 - X)^2 cos X dx

I know the derivative of sin X is cos X but this didn't make sense to me because I've never seen it done before. If the above integral is correct, then why, when I tried to solve other integrals by changing the variable from dx to dy or from dy to dx using the above method, I always got the wrong answer?

It's hard to explain, so I'm going to use an example of my point. Here's another volume problem -

"A solid has a base bounded by Y = 4 - X^2 and the X-axis. Each cross section perpendicular to the base and parallel to the X-axis is a rectangle of height 2. Find its volume."

Setting up the integral gives us -

{(0,4) 2x(2) dy

4{(0,4) x dy

So... why isn't it possible for me to do the following?

4{(-2,2) x(-2x) dx

-8{(-2,2) x^2 dx

Answer (incorrect, of course): -42 2/3

Note: The derivative of y equals -2x dx. This problem is solved correctly by replacing X with sqrt(4 - y).

I'm lost at this point. If one variable is incompatible, my instinct tells me to replace it and arctan y won't cut it. To make the integral compatible, I decided to try to replace dy with dx and change the interval (even though I knew it to be wrong somehow!) but the book gave an additional term of cos X. I've never seen it before and this method NEVER works with all integrals I've solved so far (like the last problem I just gave)! It's hard to explain, I'm just lost. :(

By the way, the answer to the first problem in the beginning is (pi - 2) units^3