C++基础二-条件判断

#include <iostream>
using namespace std;
const int score = 60;


int main() {

    //if--else if --else
    int a;

    cout << "Type num" << endl;
    cin >> a;

    if (a>score) {cout << "及格了!" << endl;}
    else if (a == score) { cout << "Luckly!" << endl; }
    else { cout << "Failed !" << endl; }
        

    //三目运算符
    int a1 = 10;
    int a2 = 20;
    int a3;
    a3 = a1 > a2 ? a1 : a2;
    cout << a3 << endl;

    //switch 执行多条件分支
    cout << "This is switch part" << endl;
    int num;
    printf("Please type number");
    cin >> num;
    switch (num)
    {
    case 10: cout << "U got 10" << endl; break;
    case 20: cout << "U got 20" << endl; break;
    case 30: cout << "U got 30" << endl; break;
    case 40: cout << "U got 40" << endl; break;
    case 50: cout << "U got 50" << endl; break;
    case 60: cout << "U got 60" << endl; break;
    default: cout << "U got default" << endl;break;
    }


    
    system("pause");
    return 0;    
}

 

posted @ 2021-01-01 21:25  y0um  阅读(144)  评论(0编辑  收藏  举报

新人优惠服务器