title: C++ Cash Register Program Not using <string>
body: <p>I have to write a program without using strings . Here is my code  : </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  
  using namespace std;
  
  struct product
  {
      char productName[100];
      double productPrice = 0;
  
  };
  
  const int MAX_CHAR = 101;
  const int MAX_ITEM = 100;
  
  int main()
  {
      product item[MAX_ITEM];
      double total = 0;
      int count = 0;
  
      for (int i = 0; i &lt; MAX_ITEM; i++)
      {
          cout &lt;&lt; "Please , enter the product name(for checkout type -1) : ";
          cin.get(item[i].productName, MAX_CHAR, '\n');
          cin.ignore(100, '\n');
  
          if (strcmp(item[i].productName, "-1") == 0 ) {
              break;
          }
          else {
              count++;
              cout &lt;&lt; "Please , enter the price for " &lt;&lt; item[i].productName &lt;&lt; " : $";
              cin &gt;&gt; item[i].productPrice;
              cin.ignore(100, '\n');
  
              total += item[i].productPrice;
              cout &lt;&lt; endl &lt;&lt; "Product entered : " &lt;&lt; item[i].productName &lt;&lt; " " &lt;&lt; "$" 
                   &lt;&lt; fixed &lt;&lt; setprecision(2) &lt;&lt;item[i].productPrice &lt;&lt; endl;
              cout &lt;&lt; "Total : $" &lt;&lt; total &lt;&lt; endl &lt;&lt; endl;
          }
  
      }
  
      cout &lt;&lt; endl &lt;&lt; "###############";
      cout &lt;&lt; endl &lt;&lt; "Your Receipt : "  &lt;&lt; endl &lt;&lt; endl;
  
      for (int i = 0; i &lt; count; i++) {
          cout &lt;&lt; item[i].productName &lt;&lt; " $" &lt;&lt; fixed &lt;&lt; setprecision(2) &lt;&lt; item[i].productPrice &lt;&lt; endl;
      }
  
      cout &lt;&lt; endl &lt;&lt; "Total : $" &lt;&lt; total;
      cout &lt;&lt; endl &lt;&lt; "###############";
  
      getchar();
      getchar();
      return 0;
  }
  </code></pre>
  
  <p>I have a couple questions :</p>
  
  <ol>
  <li><p>Why does the program crash if I don't use <code>cin.ignore(100, '\n');</code> after <code>cin &gt;&gt; item[i].productPrice;</code> ? It's just <code>cin</code> without any condition, so it should not leave a new line char in input stream?</p></li>
  <li><p>How can I check if the price doesn't contain incorrect input (so it has only decimal or floating point numbers) ?</p></li>
  <li><p>How can I check if the name contains chars and numbers which are >0 (except -1) ?</p></li>
  <li><p>Is it better to use <code>cin.getline</code> in this case ?</p></li>
  </ol>