Restrict user to input real number only in C++

前端 未结 10 1922
旧时难觅i
旧时难觅i 2021-01-15 06:40

How can I restrict the user to input real numbers only in C++ program?

Example:

double number; cin >> number;

and it won\'t accept t

10条回答
  •  梦毁少年i
    2021-01-15 07:07

    Here's some pseudo code;

    double num;
    
    while( num != realNum)   //check input is valid
    {
        cin >> num;
    }
    ....
    

提交回复
热议问题