Welcome to LQ. This smells like a homework to me... We are not here to do your homework (please read the forum rules).
However I and many others don't mind pointing you in the right direction... The error message means that you are doing some operation which expects to see an integer operand, but somehow it is not getting one.
A handy feature of bash is the -x option, which will print out what it is executing as it does it. This is after interpolation of variables and so on... You activate this by adding -x to the shabang line of your script, i.e. it should start:
Run the script with that, and you will see some useful output which should help you understand what is going on.
Oh, one last thing, please put code in [CODE] tags. This puts it in a fixed width font and preserves indentation, making it much easier to read.