title: C++ reading from text file, parsing and adding prices
body: <p>The goal is to have the program read from the text file, parse it by the # symbol, and print out the item and the price. It is in a loop so it needs to repeat because there is 3 items. It also needs to count the amount of items (based on the lines) and add all the prices together for a total price. The text file it needs to parse looks like this:</p>
  
  <pre>
  hammer#9.95
  saw#20.15
  shovel#35.40
  </pre>
  
  <p>My code is as follows: </p>
  
  <pre><code>#include &lt;string&gt; 
  #include &lt;fstream&gt;
  #include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  using namespace std;
  int main()
  {
  ifstream invoice("invoice2.txt");
  string name;
  int count = 0;
  int totalPrice = 0;
  float price = 0.0;
  while(invoice.open())
  {
      getline(file, line);
      ++count;
      for (string line; getline(file, line); )
      {
          size_t sharp = line.find('#');  
          if (sharp != string::npos)
          {
  
                  string name(line, 0, sharp);
                  line.erase(0, sharp+1);
                  price = stof(line);
              cout &lt;&lt; "*** Invoice ***\n";
              cout &lt;&lt; "----------------------------\n";
                  cout &lt;&lt; name &lt;&lt; "               $" &lt;&lt; price &lt;&lt; "\n\n";
              cout &lt;&lt; "----------------------------\n";
              cout &lt;&lt; count &lt;&lt; " items:             " &lt;&lt; totalPrice;
              }
      }
  }
  return 0;
  }
  </code></pre>
  
  <p>The loop needs to repeat until the text file is over then it should break and print the totalprice</p>