Quote Originally Posted by laserlight View Post
No, you only do that on a read error.
You're right

Code:
unsigned short method2(const string& text = "", unsigned short max = -1){
    unsigned short val;

    while (true)
    {
        cout << text;
        if (cin >> val && val <= max) break;

        cin.clear();
        cin.ignore(numeric_limits<streamsize>::max(), '\n');

        cout << "Invalid answer!\n\n";

    }
    cin.ignore(numeric_limits<streamsize>::max(), '\n');

    return val;
}


What about this? It seems better than casting the variable each time...