📜  c++ switch integer - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:56.754000             🧑  作者: Mango

代码示例1
int testScore;                     
    cout <<"Enter your test score and I will tell you \n";
    cout <<"the letter grade you earned ";
    cin >> testScore;

    switch(testScore/10)
{ 
    case 10:
    case 9:
        cout <<"Your grade is A.\n";
    break;
    case 8: 
        cout <<"Your grade is B.\n";
    break;
    case 7: 
        cout <<"Your grade is C.\n";
        break;
    case 6: 
            cout << "Your grade is D.\n";
        break;
    case 5: 
            cout << "Your grade is F.\n";
        break;

    default:
        cout << "That score isn’t valid\n";

    }