#47244: a small trick


ianliu9487168 (710-38 劉晏暢)

學校 : 臺北市私立延平高級中學
編號 : 312744
來源 : [203.72.178.2]
最後登入時間 :
2025-10-09 17:12:25

#include <iostream>
#include <limits>

using namespace std;

int main()
{
    int n;
    
    cout << "What's your age? ";
    
    while (true)
    {
        cin >> n;
        
        if (cin.fail())
        {
            cin.clear();
            cin.ignore(numeric_limits<streamsize>::max(), '\n');
            cout << "stop playing! Please enter a valid number for age: ";
        }
        else
        {
            break;
        }
    }

    cout << "I'm so glad to meet you." << endl;
    
    if (n <= 20)
        cout << "You are so young! Too small!" << endl;
    else
        cout << "You are so old!" << endl;

    return 0;
}