Let Cathy's cookies = C and Devi's cookies = D

C + D = 234

C + 8 = D

These are now simultaneous equations; taking away the second from the first leaves:

D - 8 = 234 - D

Add D to both sides:

2D - 8 = 234

Add 8 to both sides:

2D = 242

Divide both by 2:

D = 121

So Devi has 121 cookies and Cathy has 113. Now you can work out how many each gave away by forming similar equations.