title: Issues using for loops in a C++ program tasked with finding the average of each of 6 specific lines containing 25 numeric values in an XML file
body: <p>I am writing a program in C++ that is supposed to locate <a href="https://i.imgur.com/5ifCYhk.jpg" rel="nofollow">6 specific lines in an XML file, each line individually holding 25 numeric values</a>, and then find the average of those 25 numeric values for each line separately and output that average to the console window and to an output file. Additionally, I am supposed to extract the 6 time-stamps associated with those 6 specific lines. So far I have been able to implement regex to find and extract and output the 6 time-stamps with success. However, the function to find the average of the 25 numerical wattage/voltage values in each of the 6 lines outputs nothing, despite there being no compiler errors. I've tried to rubber ducky debug my code to no avail, and was hoping that a fresh pair of eyes could point out what I'm doing wrong.</p>
  
  <p><strong>Expected output:</strong> </p>
  
  <p>2014-07-08T18:14:17.716Z</p>
  
  <p>2014-07-08T18:14:18.716Z</p>
  
  <p>2014-07-08T18:14:19.716Z</p>
  
  <p>2014-07-08T18:14:20.716Z</p>
  
  <p>2014-07-08T18:14:21.716Z</p>
  
  <p>2014-07-08T18:14:22.716Z</p>
  
  <p>Average Voltage: 3924.76</p>
  
  <p>Average Voltage: 5793.68</p>
  
  <p>Average Voltage: 7149.2</p>
  
  <p>Average Wattage: 19425.5</p>
  
  <p>Average Wattage: 8799.4</p>
  
  <p>Average Wattage: 12602.9</p>
  
  <p><strong>Current Output:</strong> </p>
  
  <p><a href="http://imgur.com/JmKnF0o" rel="nofollow">http://imgur.com/JmKnF0o</a></p>
  
  <p>XML file: <a href="http://pastebin.com/5hMy9RzK" rel="nofollow">http://pastebin.com/5hMy9RzK</a></p>
  
  <pre><code>#include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;regex&gt;
  void timestamps();
  void voltAvg();
  using namespace std;
  float sum; //global variable
  ifstream infile;
  ofstream outFile;
  
  int main(){
  outFile.open("Outputdata.txt");
  infile.open("Groupproject.xml"); // Opens the XML file containing the information that is to be read
  if (infile.fail())
  {
      cout &lt;&lt; "The file is not able to be located" &lt;&lt; endl;
      system("Pause");
      exit(1);
  }
  timestamps();
  voltAvg();
  infile.close();
  outFile.close();
  system("pause");
  return 0;
  }
  
  
  void timestamps() {
  string fileinput;
  
  regex time_regex("\\d\\d\\d\\d-\\d\\d-\\d\\d\\w\\d\\d:\\d\\d:\\d\\d\\.716Z");
  smatch time_matches;
  
  
  
  while (!infile.eof()) {  //Until the end of the file is reached, obtain each line
      getline(infile, fileinput);
  
      if (regex_search(fileinput, time_matches, time_regex)) { // if regex_search is able to locate a line which has elements matching the regex expression "time_regex" output the located element
  
          cout &lt;&lt; "Timestamp: " &lt;&lt; time_matches[0] &lt;&lt; endl;
          outFile &lt;&lt; "Timestamp: " &lt;&lt; time_matches[0] &lt;&lt; endl;
  }
  
  }
  
  }
  
  void voltAvg() {
  float ave;
  float dataValues;
  int index;
  string s;
  string locateWord;
  
  getline(infile, s); //gets first line of file
  index = s.find(' '); //finds first white space
  locateWord = s.substr(0, index); //cuts up line and assigns to locateWord
  while (locateWord != "&lt;VoltAmpereReactiveTimeSeries")
  {
      getline(infile, s);
      index = s.find(' ');
      locateWord = s.substr(0, index);
  
  }
      s = s.substr(index + 1, s.length());
      infile.ignore(116, '\n'); // Ignores all of the stuff on the "&lt;VoltAmpereReactiveTimeSeries" line and gets to the numbers on the subsequent line
  
      for (int i = 0; i &lt; 3; i++) {
          for (int count = 0; count &lt; 25; count++) //sums 25 voltage/wattage values
          {
              infile &gt;&gt; dataValues;//extract voltage data values from InFile
              sum += dataValues;
          }
          ave = sum / 25.0; //calculate the average voltage
          cout &lt;&lt; "Average Voltage: " &lt;&lt; ave  &lt;&lt; endl;//outputs ave on screen
          outFile &lt;&lt; "Average Voltage: " &lt;&lt; ave &lt;&lt; endl; //Prints the average to out file
          sum = 0; // re initialize sum 
          infile.ignore(176, '\n'); 
  
      }
      for (int j = 0; j &lt; 3; j++) { 
          for (int countb = 0; countb &lt; 25; countb++) //sums 25 voltage/wattage values
          {
              infile &gt;&gt; dataValues;//extract wattage data values from infile
              sum += dataValues;
          }
          ave = sum / 25.0; //calculate the average wattage
          cout &lt;&lt; "Average Wattage: " &lt;&lt; ave &lt;&lt; endl;//outputs ave on screen
          outFile &lt;&lt; "Average Wattage: " &lt;&lt; ave &lt;&lt; endl; //Prints the average to out file
          sum = 0; // re initialize sum 
          infile.ignore(176, '\n');
  
      }
  }
  </code></pre>