#include<iostream> using namespace std; int main() { //三只小猪称重量 int a=50; int b=66; int c=98; if(a>b){ if(a>c){ cout<<a<<endl; } else{ cout<<c<<endl; } } else{ if(b>c){ cout<<b<<endl; } else{ cout<<c<<endl; } } //三目运算符 c = a > b ? a : b; cout << "c = " << c << endl; //C++中三目运算符返回的是变量,可以继续赋值 (a > b ? a : b) = 100; cout << "a = " << a << endl; cout << "b = " << b << endl; cout << "c = " << c << endl; //switch语句 //请给电影评分 //10 ~ 9 经典 // 8 ~ 7 非常好 // 6 ~ 5 一般 // 5分以下 烂片 int score = 0; cout << "请给电影打分" << endl; cin >> score; switch (score) { case 10: case 9: cout << "经典" << endl; break; case 8: cout << "非常好" << endl; break; case 7: case 6: cout << "一般" << endl; break; default: cout << "烂片" << endl; break; } return 0; }