一 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](https://img2022.cnblogs.com/blog/2827161/202204/2827161-20220407055301912-1694107057.png)
二 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](https://img2022.cnblogs.com/blog/2827161/202204/2827161-20220407055659066-1381884036.png)
三 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](https://img2022.cnblogs.com/blog/2827161/202204/2827161-20220407055935871-1253516967.png)
四 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](https://img2022.cnblogs.com/blog/2827161/202204/2827161-20220407060748422-1266343394.png)