title: C++ test if input is an double/char
body: <p>I am trying to get input from the user and need to know a way to have the program recognize that the input <strong>was</strong> or <strong>was not</strong> a double/char this is what i have right now... but when you type an incorrect type of input
        <p>1) the double test one just loops infinatly</p>
        <p>2) the char one won't stop looping even with the correct imput</p>
  
  <pre><code>int main () {
      double _double = 0;
      bool done = true;
  while ( done ) {
      cout &lt;&lt; "Please enter a DOUBLE:\n" &lt;&lt; endl;
      cin &gt;&gt; _double;
      if ( _double &gt; 0 ) { done = false; }
      if ( _double &lt; 0 ) { cout &lt;&lt; "\nthe number you entered was less than zero\nplease enter a valad number..." &lt;&lt; endl; } 
      if(cin.fail()) { cin.clear(); }
  }
  
  done = false;
  char _char = ' ';
  while ( !done ) {
      cout &lt;&lt; "Please enter a CHAR" &lt;&lt; "\n";
      cout &lt;&lt; "\t'y' = yes\n\t'n' = no" &lt;&lt; endl;
      cin &gt;&gt; _char;
      if ( _char == 'y' || _char == 'n' ) { done = true; }
      if ( ! (_char == 'y' || _char == 'n') ) { cout &lt;&lt; "\nyou have entered an invald symbol... \n" &lt;&lt; endl; }
      if(cin.fail()) { cin.clear(); }
  }
  </code></pre>