title: Shuffling an array with a set of rules and returning the value from the function
body: <p>I am relatively new to C++, I have only started learning it this year.
  I am having trouble writing a little program to take in a text document and store it in an array. Then take that array and randomise the values in a certain way. It is for a rostering program to arrange the riders + horses into suitable positions.</p>
  
  <p>What I am trying to attempt in this function (gen() ) is to copy the entry[num] to entry2[num2] . Where num is the amount of entries there are, and num2 is a randomly generated rand() number. I then wanted it to check if the new entry is atleast 15 positions more then the old entry (in this case.. so the rider of the horse can have a break before his next event)</p>
  
  <p>so as you can guess .. this application doesnt work, im guessing there is an easier way?
  How can I send the variables into this array, And how can I get this function to return the array back to my main .. im guessing via a pointer?</p>
  
  <p>I have attached the whole code below.</p>
  
  <pre><code>/*   ________________________________________________________________________________
  *    |   TITLE:     main.cpp                                                        |
  *    |   AUTHOR:    Samuel Abbott (samuel.d.abbott@gmx.com)                         |
  *    |   PURPOSE:   to take camp draft data in, randomise it with certain values,   |
  *    |              and output the new roster as a text document                    |
  *    |   DATE:      may 1, 2012                                                     |
  *    |   LAST EDIT: may 3,2012                                                      |
  *    |______________________________________________________________________________|
  */
  
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;stdlib.h&gt; //random number
  #include &lt;time.h&gt; //random number
  #include &lt;fstream&gt; //used for input / output of external files
  
  using namespace std;
  /*
  *   TITLE: gen
  *   PURPOSE: to randomise the entries , check to see if they are more then 15 units  apart, and return a pointer to the randomised array
  *   string entry[] holds original values
  *   int num [] holds number of entries
  */
  sting gen(string entry[], int num)
  {
     int count = 0;
     string entry2[num]; //randomised array
  
     /* initialize random seed: */
     srand(time(NULL));
  
     for (count =0; count &lt; num)
     {
        num2 = rand() % num; //generate random number
        entry[num] = entry2[num2]; //copy number from array to a random position in the next array
  
        /* a series of if checks to make sure the entry is no less then 15 positions from the previous entry */
        if (entry2[num2]=entry[num-15])
        {
           num2 = rand() % num; //generate random number
           entry[num] = entry2[num2]; //copy number from array to a random position in the next array
        }
  
        else if (entry2[num2]=entry[num-14])
        {
           num2 = rand() % num; //generate random number
           entry[num] = entry2[num2]; //copy number from array to a random position in the next array
        }
  
        else if (entry2[num2]=entry[num-13])
        {
           num2 = rand() % num; //generate random number
           entry[num] = entry2[num2]; //copy number from array to a random position in the next array
        }
  
        else if (entry2[num2]=entry[num-12])
        {
           num2 = rand() % num; //generate random number
           entry[num] = entry2[num2]; //copy number from array to a random position in the next array
        }
  
        else if (entry2[num2]=entry[num-11])
        {
           num2 = rand() % num; //generate random number
           entry[num] = entry2[num2]; //copy number from array to a random position in the next array
        }
  
        else if (entry2[num2]=entry[num-10])
        {
           num2 = rand() % num; //generate random number
           entry[num] = entry2[num2]; //copy number from array to a random position in the next array
        }
  
        else if (entry2[num2]=entry[num-9])
        {
           num2 = rand() % num; //generate random number
           entry[num] = entry2[num2]; //copy number from array to a random position in the next array
        }
  
        else if (entry2[num2]=entry[num-8])
        {
           num2 = rand() % num; //generate random number
           entry[num] = entry2[num2]; //copy number from array to a random position in the next array
        }
  
        else if (entry2[num2]=entry[num-7])
        {
           num2 = rand() % num; //generate random number
           entry[num] = entry2[num2]; //copy number from array to a random position in the next array
        }
  
        else if (entry2[num2]=entry[num-6])
        {
           num2 = rand() % num; //generate random number
           entry[num] = entry2[num2]; //copy number from array to a random position in the next array
        }
  
        else if (entry2[num2]=entry[num-5])
        {
           num2 = rand() % num; //generate random number
           entry[num] = entry2[num2]; //copy number from array to a random position in the next array
        }
  
        else if (entry2[num2]=entry[num-4])
        {
           num2 = rand() % num; //generate random number
           entry[num] = entry2[num2]; //copy number from array to a random position in the next array
        }
  
        else if (entry2[num2]=entry[num-3])
        {
           num2 = rand() % num; //generate random number
           entry[num] = entry2[num2]; //copy number from array to a random position in the next array
        }
  
        else if (entry2[num2]=entry[num-2])
        {
           num2 = rand() % num; //generate random number
           entry[num] = entry2[num2]; //copy number from array to a random position in the next array
        }
  
        else if (entry2[num2]=entry[num-1])
        {
           num2 = rand() % num; //generate random number
           entry[num] = entry2[num2]; //copy number from array to a random position in the next array
        }
  
        else
        {
           entry[num] = entry2[num2];
        }
     }
  
     string pointer* = entry2[]
     return pointer
  }
  
  /*
  *   Title : Loading
  *   Purpose: This function generates a loading animation. in other words. just a fancy     graphic.
  *   HAS NO LOADING PURPOSE
  */
  
  void loading()
  {
     /* Declare loading variable, this variable is just the screen printout */
     string loading = "...";
     int time = 0;
     int loadtime = 10;
  
     /* print out loading animation */
     while (time != loadtime)
     {
        cout &lt;&lt; loading;
        time++;
     }
  
  }
  void loading();
  
  /*
  *   Title: Main
  *   Purpose: this is the main function for the randomisation program
  */
  int main()
  {
  //declare all variables
     string fname = "";
     int count;
  
     string line;
     ifstream inputfile;
     char c;
     int num=0;
  
  
     /* introduction */
     cout &lt;&lt; "Roster Randomisation Generator" &lt;&lt; endl;
     /* Get input for roster name */
     cout &lt;&lt; "Enter a name for the roster, such as 13022012coolah:"&lt;&lt;endl;
     cin&gt;&gt; fname;
     /* Begin generating roster */
     cout &lt;&lt; "Roster Generation in progress." &lt;&lt; endl;
     loading();
     /* get amount of lines in text file .. used to determine how many entries there are to     avoid printing blank spaces*/
  
     inputfile.open("output.txt");
  
     while (inputfile.good())
     {
        c = inputfile.get();
  
        if (c=='\n')
        {
           num++;
        }
     }
  
     inputfile.close();
     cout&lt;&lt;"Number of Entries counted is: "&lt;&lt;num&lt;&lt;endl;
  
     string entry[num];
  
     cout &lt;&lt; "Grabbing entries from entry file..."&lt;&lt;endl;
     /* open text file*/
     inputfile.open("output.txt");
  
     /* read all data into the array entry[] */
     for (count = 0; count &lt; num; count++)
     {
        getline(inputfile,line);  //Gets a single line from example.txt
        entry[count]=line;
  
        // inputfile &gt;&gt; entry[count];
     }
  
     inputfile.close();
     cout &lt;&lt;"Found the following entries: " &lt;&lt;endl;
  
     /* output captured entries*/
     for (count =0; count &lt; num; count++)
     {
        cout &lt;&lt;entry[count] &lt;&lt;endl;
     }
  
  
     return 0;
  }
  </code></pre>