   Input test
  Ok noob question.basicaly i have this code    #include <iostream>using namespace std;int main(){int a;cout << "Enter an integer value ";cin >> a;return 0;}i just want to know how to check that the value the user has inputed is actualy an int. eg/ i want to make sure they havnt jst pressed ''a'' or sumthing.Thanks in advanced. 
  This is how I'd handle it:  #include <iostream>using namespace std;int main(){int a;cout << "Enter an integer value between 1-1000 ";cin >> a;if(a > 1000 || a < 1)cout << "Follow instructions!!" << endl;elsecout << "Your Number is: " << a << endl;return 0;}It'll complain if you enter 'a', or anything else that's not what it asks for.   [edited by - xegoth on February 10, 2004 3:27:03 PM];  Ok sry its my fault for not being specific. Im looking for more of a generalised code so that i can adapt it for say, testing for chars, floats and doubles e.t.c I Realy need it to be able to to test for any variable type not just integers. ;quote: #include <iostream>using namespace std;int main(){int a;cout << "Enter an integer value between 1-1000 ";cin >> a; if(a > 1000 || a < 1)cout << "Follow instructions!!" << endl;elsecout << "Your Number is: " << a << endl;return 0;} That won't work try putting that in a loop and then entering any letter and see what happens  The reason I believe is that when you do that it causes cin to fail so what you need to do is check and correct the problem. if(cin.fail()) //cin failed {   //correct the problem   cin.clear();   cin.ignore(1000,'\n');   //handle error here }    [edited by - PatrickD on February 10, 2004 4:51:57 PM];  Input a char, and compare the value if it''s an ASCII-code for a digit!   --You''re Welcome,Rick Wong- sitting in his chair doing the most time-consuming thing.. ;  PatrickD That code worked and is exactly what i was asking for, thank you every one. 