for (int i=0; i < size; i++)
{
while( work1 < size )
{
if(fahad[i-1]+daysOff1 < size){
fahad[i] = fahad[i-1] + daysOff1 + 1;
work1 = fahad[i];
i++;
}
}
}
The first time round this loop variable
i
will have the value
0
. But you are trying to address an element of the array by
[i - 1]
which is invalid, and will produce a random value. This makes it quite likely that you will set
fahad[i]
, and thence
work1
, to a number larger than
size
which will cause the infinite loop.
You need to check in your loops that you do not try to address elements before the beginning or beyond the end of your arrays.