知识库

C++语言开发示例:16. 并且2

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

more_and.cpp

#include <iostream>

const char *qualify[4] =
    {
        "1,000-meter race.\n",
        "mud tug-of-war.\n",
        "masters canoe jousting.\n",
        "pie-throwing festival.\n"};

int main()
{
    using namespace std;
    int age;
    cout << "Enter your age in years: ";
    cin >> age;
    int index;
    if (age > 17 && age < 35)
    {
        index = 0;
    }
    else if (age >= 35 && age < 50)
    {
        index = 1;
    }
    else if (age >= 50 && age < 65)
    {
        index = 2;
    }
    else
    {
        index = 3;
    }
    cout << "You qualify for the " << qualify[index];
}
转载请注明转自www.hylab.cn,原文地址:C++语言开发示例:16. 并且2

评论 (0)

登录后发表评论

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