if语句

一 if语句

#include <iostream>
#include <Windows.h>

using namespace std;

int main()
{
    int year = 0;

    cout << "你来公司几年了?";
    cin >> year;

    if (year > 5)
    {
        cout << "前辈,你好" << endl;
    }

    system("pause");
    return 0;
}

image

二 if...else语句

#include <iostream>
#include <Windows.h>

using namespace std;

int main()
{
    int year = 0;

    cout << "你来公司几年了?";
    cin >> year;

    if (year > 5)
    {
        cout << "你有10天年假" << endl;
    }
    else
    {
        cout << "你有3天年假" << endl;
    }

    system("pause");
    return 0;
}

image

三 if...else if...else语句

#include <iostream>
#include <Windows.h>

using namespace std;

int main()
{
    int year = 0;

    cout << "你来公司几年了?";
    cin >> year;

    if (year < 3)
    {
        cout << "你有3天年假" << endl;
    }
    else if(year > 10)
    {
        cout << "你有10天年假" << endl;
    }
    else
    {
        cout << "你有5天年假" << endl;
    }

    system("pause");
    return 0;
}

image

四 if语句的嵌套

#include <iostream>
#include <Windows.h>

using namespace std;

int main()
{
    int a, b, c;

    cout << "请输入3个整数:";
    cin >> a >> b >> c;

    if (a > b)
    {
        if (a > c)
        {
            cout << "最大值:" << a << endl;
        }
        else
        {
            cout << "最大值:" << c << endl;
        }
    }
    else
    {
        if (b > c)
        {
            cout << "最大值:" << b << endl;
        }
        else
        {
            cout << "最大值:" << c << endl;
        }
    }

    system("pause");
    return 0;
}

image

posted @   荒年、  阅读(33)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示