title: C++ - cin allows to save non-numeric in double type
body: <p>i have a problem with this code. Everything seems to be working fine but when you type something like this: 123aaaddfa123 then program will accept this as double value. Any ideas to avoid this problem? Thank you.</p>
  
  <pre><code>int main ()
  {
     const char MAX = 5;
     cout &lt;&lt; "Weight of your fishes (maximum 5)" &lt;&lt; endl;
     double fishes[MAX];
     char count = 0;
     while (count &lt; MAX)
     {
        cout &lt;&lt; count + 1 &lt;&lt; ". fish: " &lt;&lt; endl;
        if (cin &gt;&gt; fishes[count])
            count++;
        else {
            cin.clear();
            if (cin.get() == 'q') //no more fishes = quit
                break;
            while (cin.get() != '\n') //clearing cin buffer
                continue;
        }
     }
  
  if (count &gt; 0) {
      double sum = 0;
      for (int i = 0; i &lt; MAX; ++i) {
          sum += fishes[i];
      }
      cout &lt;&lt; "Avarage weight of your " &lt;&lt; (int)count &lt;&lt; " fishes is: " &lt;&lt; sum / count &lt;&lt; " KG" &lt;&lt; endl;
  }
  </code></pre>
  
  <p>}</p>