Can anyone spot the error in my code? The program will enter the last while loop but continue in an infinite loop... I figured fresh eyes may help spot the flaw!

int xlist[1500], ylist[1500], counter = 0, tempx, tempy, tempcounter;
    bool assign = false;
    while(counter < 1500)
    {
        xlist[counter] = -1;
        counter++;
    }
    counter = 0;
    while(counter < 1500)
    {
        ylist[counter] = -1;
        counter++;
    }
    counter = 0;
    while(counter < 1500)
    {
        tempx = (rand() % 500);
        tempy = (rand() % 500);
        while(tempcounter < counter)
        {
            if(xlist[tempcounter] != tempx || ylist[tempcounter] != tempy)
            {
                assign = true;
                tempcounter++;
            }
            else
            {
                tempcounter = 0;
                assign = false;
                break;
            }
        }
        tempcounter = 0;
        if(assign)
        {
            xlist[counter] = tempx;
            ylist[counter] = tempy;
            counter++;
        }
    }

Recommended Answers

All 3 Replies

Haha yeah that was part of it! But for some reason its still not working... I wonder if it can compare correctly with xlist[tempcounter]?

Oh wait I found it nevermind! And thanks Salem!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.