using the following code:

-------------------------------------------------
#include <iostream>

using namespace std;

int main()
{
int num = 0;
cin >> num;

while (num < 1 || num > 170)
{
cout << "You entered an invalid number, try again:" << endl;
cin >> num;
}

cout << num;

return 0;
}

----------------------------------------------

everything works fine unless i input a character, which prints the cout message over and over again to the screen.

can someone help me with this please