I'm trying to find all primes below a certain number, which is the square root of some original number. By finding all the primes below the original numbers square root and dividing the original by the found primes, you can tell if the original number is prime (for people that didn't know that). So... here is my function to find all the prime numbers below a certain number. However, I am getting a runtime error and the program needs to close whenever I try it. I'm not quite sure on what is happening, and maybe I've stared at it too long. Does anyone see anything that is either out of bounds, a problem, or a fix etc.

Code:

bool FindPrimes(int upper, int values[]) //upper needs to be square root of the original number
{
int index = 0, pRet = 1, loop = 0, ret = 0;
bool bRet = true; //automatically assume first number is prime, which is 2 anyways
for(loop = 2;loop <= upper; loop++){ //start the loop at 2 since it is the first prime
bRet = true;
for(int i = 0; i <= index; i++){
ret = loop % values[i]; //check if there are any remainders, remainder = 0 means not prime
if(ret == 0){
bRet = false; //the value was not prime
break;
}
}
if(bRet){
values[index] = loop; //add the loop value to the array of int's if it is not divisible by any prime thus far
index++; //increase the index count
}
}
return true;
}