Just want to start off apologizing if this has been answered and just should be worded differently so I was unable to find it. I've been working on this particular problem for a few hours and it's possible my Google Fu is weak atm.
For my c++ class I have to create a random number generator that collects data from the user to specify the number of digits the numbers must be and the number of rands to create. I can create the randoms just fine, the only problem is the numbers can not duplicate at any point and the if loop I created at the end to decrement returns true always and I can't figure out why. Because of this, the loop never moves on to increment i. If I'm not mistaken, it should not even be possible to have a duplicate entry on the first try right?
void TargetGen::genNumbers()
{
int mod = 0;
int baseMod = 0;
if(Digits != 1)
{
baseMod = pow(10.0,(Digits -1));
}
mod = (pow(10.0,Digits))-baseMod;
for(int i=0;i<Numbers;i++)
{
cout << "front of i loop, value of i: " << i << endl;
int randomTemp;
randomTemp = rand() % mod + baseMod;
targets[i] = randomTemp;
cout << "rand: " << targets[i] << endl;
for(int k = 0;k <= Numbers; k++)
{
if(targets[k] == targets[i])
{
cout << targets[i] << endl;
i--;
}
cout << " k looping, k value: " << k << endl;
cout << " k loop, value of i: " << i << endl;
}
}
}