try this
Code:
#include<iostream>
#include <limits>
using namespace std;
int main()
{
int a;
while(1)
{
cout << "please enter a number\n";
cin >>(int)a;
if((a>0)&&(a%2))
{
cout << "You have entered an odd positive number\n";
}
/*
* The stream will go into an error state if it is expecting an integer
* but it only sees characters for example. To move on, you must first clear
* the error flags by using the clear member function. Then you must get rid of
* the bad data in the input stream by using the ignore member function.
* After that, you can attempt to get more input.
*
*/
cin.clear();
// include <limits> and then use numeric_limits<streamsize>::max()
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
return 0;
}