知识库

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

2025-02-01 20:28:44 李腾 1 次阅读

or.cpp

#include <iostream>

int main()
{
    using namespace std;
    cout << "This program may reformat your hard disk\n"
            "and destroy all your data.\n"
            "Do you wish to continue? <y/n> ";
    char ch;
    cin >> ch;
    if (ch == 'y' || ch == 'Y')
    {
        cout << "You were warned!\a\a\n";
    }
    else if (ch == 'n' || ch == 'N')
    {
        cout << "A wise choioce ... bye\n";
    }
    else
    {
        cout << "That wasn't a y or n! Apparently you "
                "can't follow\ninstructions, so "
                "I'll trash your disk anyway.\a\a\a\n";
    }
}
转载请注明转自www.hylab.cn,原文地址:C++语言开发示例:14. 或者

评论 (0)

登录后发表评论

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