5.Switch Case

#include <bits/stdc++.h>
using namespace std;
int main(){
    int x , a , b;
    cin >> a >> x >> b;
    /*
        switch (變數名稱){
            case ? : 
                ......
                ......
                break;
        }
    */
    // switch 就像 if()
    switch(x){
        case 1:
            cout << a + b << endl;
            break;
        case 2:
            cout << a - b << endl;
            break;
    }
    /*
        if(x == 1) cout << a + b << endl;
        else if(x == 2) cout << a - b << endl;
    */
    return 0;
}

results matching ""

    No results matching ""