corrected issue with pages causing compiler errlr

You used the pages variable before instantiating it, thus your problem. I have set it to the mathematical operation for the pages variable and all is well.