title: How to pass and return arrays in C++?
body: <p>I am making a simple bank account handling system and am saving the account information as an array however I have come across difficulties when it comes to passing the account information, I am reading the array from a text file into the program but this needs to be passed from the function that reads the file to the functions that handle the withdraws, deposits and viewing the balance, the array that is passed is intended to store the current balance, a stand in for a bool for the overdraft as well as the last 3 withdraws and deposits.</p>
  
  <p>the withdraw function looks like</p>
  
  <pre><code>float Withdraw()                                        //function handled withdraw requests
  {
  //variables
  const int M = 3;                                //declare const int for withdraws
  const int N = 8;                                //declare const int for account
  float withdrawAmount = 0.0f;                    //used for internam laths in function   
  float currentBalance = 0.0f;                    //used internally in function
  float newBalance = 0.0f;                        //passed to write function
  float withdraws[M];                             //passed to write function
  float account[N];                               //passed and returned from read function
  //call readFile function
  readFile(account[N]);
  
  cout &lt;&lt; account[0];
  //user interface
  cout &lt;&lt; "Withdraw opnened" &lt;&lt; endl;                 //prompts user for input of a withdraw amount and displays current balance
  cout &lt;&lt; "Your Current Balance is: " &lt;&lt; currentBalance &lt;&lt; endl;
  cout &lt;&lt; "How Much Would You Like to Withdraw?" &lt;&lt; endl;
  cin &gt;&gt; withdrawAmount;
  newBalance = currentBalance - withdrawAmount;           //calculates balance after withdraw
  withdraws[2] = withdraws[1];
  withdraws[1] = withdraws[0];
  withdraws[0] = withdrawAmount;
  system("PAUSE");
  system("cls");
  
  writeFile(newBalance, withdraws[M]);
  Menu();
  return 0;
  }
  </code></pre>
  
  <p>and the function to read the file looks like</p>
  
  <pre><code>float readFile(float account[8])
  {
  //variables
  const int N = 8;
  float accountRead[N];
  
  //read file
  ifstream file("floats.txt");
  if (!file.is_open())
  {
      cerr &lt;&lt; "Error opening file" &lt;&lt; endl;
      return 0;
  }
  for (int i = 0; i &lt; N &amp;&amp; file &gt;&gt; accountRead[i]; ++i)
      ;
  if (file)
  {
  }
  account = accountRead;
  return account[N];
  }
  </code></pre>
  
  <p>any guidance would be greatly appreciated as I have spent hours trying to research this but have gotten nowhere</p>