Input Validation (don't know what I did wrong)

Hello guy, I'm new here
I finally got figure it out how to stop infinite loop when I input a character instead of integer. Now I can't input integer first because it want character first. I want to make character read as no letters and double read as no integer what am I doing wrong here?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
cout
			<< "\nPart 1 (validate an integer) \n"
			<< "Enter a number: ";
		cin >> insert;       cin.ignore(80, '\n');

		while (!(cin >> insert) || insert !=(int)insert)
		{
			if (!(cin >> insert))
			{
				cin.clear(); cin.ignore(80, '\n');
				cout << "Please no letters: ";
				
			}
			else 
			{
				cin.clear(); cin.ignore(80, '\n');
				cout << insert <<" not an integer: ";
				
			}
		}
		cout << "Good! " << insert << " is an integer!" << endl;

		cin.get();
Try something like this.

1
2
3
4
5
6
7
8
9
10
     cout << "Enter a number: ";
     cin >> insert;     
)
     while (!cin.good()){
           cout << "Error msg: ";             
           cin.clear();
           cin.ignore(80, '\n');
           cin >> insert;
}
I believe I'm not suppose to use cin.good() yet.

I'm trying to make while(!(reading this) || (that)) and print out either one of the two as I input character or double.
See if this helps at all:
http://www.lb-stuff.com/user-input
Topic archived. No new replies allowed.