title: Reading data from text files, assigning to arrays, and printing
body: <p>Just a disclaimer: this exercise was already due and I presented it incomplete, but wanted to follow up and understand my mistakes.</p>
  
  <p>The requirements were to read the contents of two text files, assign their (floating point) values to 2D matrices, and print them to console. There was other requirements, but they aren't relevant to the issue at hand.</p>
  
  <p>From my troubleshooting, there is either something wrong with the reading of these files, or something wrong with how they are printed.</p>
  
  <p>Below is the contents of each text file:</p>
  
  <p>file 1:</p>
  
  <pre><code>81.51310482 91.38325441 27.8637468  96.53709795
  90.6244833  63.26754258 54.715496   15.76918882
  12.70503097 9.75891752  95.79855889 97.10780782
  </code></pre>
  
  <p>file 2:</p>
  
  <pre><code>80.69838114 90.46987855 27.58524858 95.57220941
  89.71869137 62.63518334 54.16861448 15.61157574
  12.57804415 9.661377115 94.84105205 96.13721503
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;cmath&gt;
  #include&lt;fstream&gt;
  #include&lt;string&gt;
  #include&lt;stdlib.h&gt;
  int r,ro,c,co,iter;
  float ary,avg,a1[3][4],a2[3][4];
  
  std::ifstream fs;
  std::string line;
  void assignarray(int iter,float ary);
  void printarray(int iter);
  
  int main(){
  //select text files
  for(iter=1;iter&lt;3;iter++){
      if(iter==1){
          fs.open("table_1.txt");
          ary=a1[r][c];}
      else if(iter==2){
          fs.open("table_2.txt");
          ary=a2[r][c];}
  if(fs.is_open()){
      //std::cout&lt;&lt;"File was successfully opened.\n";
      assignarray(iter,ary);
      printarray(iter);
      fs.close();}
  else{
      std::cout&lt;&lt;"There was a problem opening or writing to the destination file, please try again.\n";
      return 1;}
      }
  std::cout&lt;&lt;"Please input the coordinates for the row and column of both arrays, the entries of which will be averaged.\nInput format: R C\n";
  std::cin&gt;&gt;ro&gt;&gt;co;
  avg=(a1[ro][co]+a2[ro][co])/2;
  std::cout&lt;&lt;"The average of the entries sharing coordinates Row "&lt;&lt;ro&lt;&lt;" and Column "&lt;&lt;co&lt;&lt;" is:"&lt;&lt;avg&lt;&lt;"\n";    
  }
  
  void assignarray(int iter,float ary){
  while(std::getline(fs,line)){
      for(r=0;r&lt;3;r++){//increment from row value 1 to 3
          for(c=0;c&lt;4;c++){//increment column from 1 to 4
              fs&gt;&gt;ary;
              }
          }
      }
  }
  void printarray(int iter){//looks good
  std::cout&lt;&lt;"table_"&lt;&lt;iter&lt;&lt;".txt contains the following values:\n";
      for(r=0;r&lt;3;r++){
          for(c=0;c&lt;4;c++){
              std::cout&lt;&lt;ary&lt;&lt;' ';
          }
      std::cout&lt;&lt;"\n";//line break after each row has been filled; creates columns
      }
  }
  </code></pre>
  
  <p>Here is part of the (erroneous) output:</p>
  
  <pre><code>table_1.txt contains the following values:
  0 0 0 0
  0 0 0 0
  table_2.txt contains the following values:
  6.58383e-039 6.58383e-039 6.58383e-039 6.58383e-039 
  6.58383e-039 6.58383e-039 6.58383e-039 6.58383e-039 
  </code></pre>
  
  <p>The part I was testing out the most was the interior of the <code>assignarray</code> void function. I've done a lot of research to come this far, but it's the first time I'm applying most of these concepts; it didn't work too smoothly. Let me know what you think, and/or how I could rectify this. Additionally, let me know if there is more information I could provide for clarification.</p>
  
  <p>Thanks.</p>
  
  <p>P.S. For whatever reason, I'm not supposed to use C++11 or newer revisions. I would appreciate it if your suggestions keep this in mind.</p>