一、基于逻辑运算符完成复杂判断
二、代码实践
#include "iostream"
using namespace std;
int main()
{
// !
// int num = 0;
// if(num) {
// cout << "if被执行" << endl;
// }else {
// cout << "else被执行" << endl;
// }
// &&
// int age,height;
// cout << "请输入年龄和身高" << endl;
// cin >> age >> height;
// // 同时满足年龄小于18和身高小于120cm才可免费
// if(age < 18 && height < 120) {
// cout << "免费游玩" << endl;
// }else {
// cout << "不可以免费游玩" << endl;
// }
// ||
int age,height;
cout << "请输入年龄和身高" << endl;
cin >> age >> height;
// 满足年龄小于18或者身高小于120cm才可免费
if(age < 18 || height < 120) {
cout << "免费游玩" << endl;
}else {
cout << "不可以免费游玩" << endl;
}
return 0;
}
适用于条件较少的情况