Giving a random number to an array
<p>Good day all. I have a rather weird thing happening to my code. I am wanting to create a random number to input into my quest_postition array to use it in my grid array. I want the location to be different every time you run the program. </p>

<p>What it is currently doing is going into a infinite loop and displaying the grid all the way down. </p>

<p>Here is my code:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
#include &lt;stdlib.h&gt;
#include &lt;time.h&gt;


using namespace std;

void draw_grid()
{

char grid[9][9] = { {'x','x','x','x','x','x','x','x','x'},
                    {'x','x','x','x','x','x','x','x','x'},
                    {'x','x','x','x','x','x','x','x','x'},
                    {'x','x','x','x','x','x','x','x','x'},
                    {'x','x','x','x','x','x','x','x','x'},
                    {'x','x','x','x','x','x','x','x','x'},
                    {'x','x','x','x','x','x','x','x','x'},
                    {'x','x','x','x','x','x','x','x','x'},
                    {'x','x','x','x','x','x','x','x','x'}};
char character = '*';
char quest = 'Q';

int position[2] = {4,4};
int quest_position[2];

srand(time(NULL));

quest_position[0] = rand() % 9 + 0;
quest_position[1] = rand() % 9 + 0;

char direction;

for(int i = 0; i &lt; 9; i++){
    for (int j = 0; j &lt; 9; j++){
        if(i == position[0] &amp;&amp; j == position[1])
            cout &lt;&lt; character;
        if(i = quest_position[0] &amp;&amp; j == quest_position[1])
            cout &lt;&lt; quest;
        else
            cout &lt;&lt; grid[i][j];
        cout &lt;&lt; " ";
    }
    cout &lt;&lt; endl;
   }
}

int main()
{
    draw_grid();
}
</code></pre>

<p>Please can you help. </p>

<p>Thanks. </p>
