switch 语句
#include <iostream>
using namespace std;
int main ()
{
// 局部变量声明
char grade = 'D';
switch(grade)
{
case 'A' :
cout << "很棒!" << endl;
break;
case 'B' :
case 'C' :
cout << "做得好" << endl;
break;
case 'D' :
cout << "您通过了" << endl;
break;
case 'F' :
cout << "最好再试一下" << endl;
break;
default :
cout << "无效的成绩" << endl;
}
cout << "您的成绩是 " << grade << endl;
return 0;
}
? : 运算符
//三目运算嵌套
#include<iostream>
using namespace std;
int main(){
int a,b,c,d,max;
cout<<"请输入三个数字:";
cin>>a>>b>>c;
max=(d=a>=b?a:b)>=c?d:c;
cout<<"最大值为:"<<max<<endl;
return 0;
}