知识库

C++语言开发示例:17. 或者

2025-02-01 20:29:00 李腾 1 次阅读

not.cpp

#include <iostream>
#include <climits>

bool is_int(double);

int main()
{
    using namespace std;
    double num;

    cout << "Yo, dude! Enter an integer value: ";
    cin >> num;
    while (!is_int(num))
    {
        cout << "Out of range -- please try again: ";
        cin >> num;
    }
    int val = int(num);
    cout << "You've entered the integer " << val << "\nBye\n";
}

bool is_int(double x)
{
    if (x < INT_MAX && x >= INT_MIN)
    {
        return true;
    }
    else
    {
        return false;
    }
}
转载请注明转自www.hylab.cn,原文地址:C++语言开发示例:17. 或者

评论 (0)

登录后发表评论

暂无评论,快来发表第一条评论吧!