title: C++ - Returning an array to main function and passing array to another function
body: <p>I'm having trouble with returning an array from a function to the main function. The array is also used as a parameter for another function.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  #include &lt;cmath&gt;
  #include &lt;cstdlib&gt;
  using namespace std;
  
  void ran(int list[]);
  void guess(int list[]);
  int black_marker(int num1[], int num2[]);
  
  int main(){
      int r[4];
      int g[4];
      cout &lt;&lt; black_marker(ran(r), guess(g));
  }
  
  void ran(int list[]){       //random number generator
      srand (time(NULL));
      int a = rand() % 6 + 1;
      int b = rand() % 7 + 1;
      while(a == b)
          b = rand() % 7 + 1;
      int c = rand() % 8 + 1;
      while(a == c || b == c)
          c = rand() % 8 + 1;
      int d = rand() % 9 + 1;
      while(a == d || b == d || c == d)
          d = rand() % 9 + 1;
  
      int num_random[4] = {a, b, c, d};
  }
  
  void guess(int list[]){         //takes user input for a guess
      int random_no[4];
      for(int i = 0; i &lt; 4; i++){
          cin &gt;&gt; random_no[i];
      }
  }
  
  int black_marker(int num1[], int num2[]){   //Counts how many digits from random number
      int black_count = 0;                    //is similar to the user's guess
      for(int i = 0; i &lt; 4; i++){
          if(num1[i] == num2[i]){
              black_count += 1;
          }
      }
      return black_count;
  }
  </code></pre>
  
  <p>Basically, this is an incomplete number-guessing game where the user is given a hint such as the number of digits that are common to the randomly generated number and the user input guess. I get a void type error for <code>cout &lt;&lt; black_marker(ran(r), guess(g));</code> which is unusual since this pass-by-reference method works otherwise when I have a cout statement in the void function's body.</p>