title: Why does program complain of too many commas?
body: <p>Here is my code, I have attached the screenshot of what output Zybooks expects, and what my output is. I am trying to get it to output exactly what Zybooks is asking, however something seams to be wrong. It is compiling though. Or maybe Zybooks is just being stupid?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;sstream&gt;
  #include &lt;iomanip&gt;
  #include &lt;cstring&gt;
  
  using namespace std;
  
  int main() {
  
      string title;
      string col1;
      string col2;
      string val;
      int numCommas = 0;
      vector&lt;string&gt; stringData;
      vector&lt;int&gt; intData;
  
      cout &lt;&lt; "Enter a title for the data:" &lt;&lt; endl;
      getline(cin, title);
      cout &lt;&lt; "You entered: " &lt;&lt; title &lt;&lt; endl &lt;&lt; endl;
  
      cout &lt;&lt; "Enter the column 1 header:" &lt;&lt; endl;
      getline(cin, col1);
      cout &lt;&lt; "You entered: " &lt;&lt; col1 &lt;&lt; endl &lt;&lt; endl;
  
      cout &lt;&lt; "Enter the column 2 header:" &lt;&lt; endl;
      getline(cin, col2);
      cout &lt;&lt; "You entered: " &lt;&lt; col2 &lt;&lt; endl &lt;&lt; endl;
  
      while (1) {
          cout &lt;&lt; "Enter a data point (-1 to stop input):" &lt;&lt; endl;
          getline(cin, val);
  
          if (val == "-1") {
              break;
          }
  
          if (val.find(',') == -1) {
              cout &lt;&lt; "Error: No comma in string." &lt;&lt; endl &lt;&lt; endl;
          }
          else {
              for (int i = 0; i &lt; val.length(); i++) {
                  if (val.at(i) == ',') {
                      numCommas++;
                      if (numCommas &gt; 1){
                          break;
                      }
                  }
              }
  
              if (numCommas == 1) {
                  stringData.push_back(val.substr(0, val.find(',')));
                  intData.push_back(stoi(val.substr(val.find(',') + 1, val.length() - 1)));
                  cout &lt;&lt; "Data string: " &lt;&lt; val.substr(0, val.find(',')) &lt;&lt; endl;
                  cout &lt;&lt; "Data integer: " &lt;&lt; stoi(val.substr(val.find(',') + 1, val.length() - 1)) &lt;&lt; endl;
              }
              else {
                  cout &lt;&lt; "Error: Too many commas in input." &lt;&lt; endl &lt;&lt; endl;
              }
          }
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Thanks.   </p>
  
  <p><a href="https://i.stack.imgur.com/TlsNz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TlsNz.png" alt="enter image description here"></a></p>
  
  <p>Thanks.   </p>