Well the problem is here


for(int d=5;d>=1;d--)

It's alway going to run 5 times. I see what your trying to do. yOu could if you were feeling clever write an algorithm so d is set to a value...