返回列表 發帖

switch 判斷式

本帖最後由 tonyh 於 2013-3-23 14:53 編輯

成績分級程式
90分~100分  優
  80分~89分  甲
  70分~79分  乙
  60分~69分  丙
    0分~59分  丁
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int score, level;
  7.     cout<<"請輸入你的成績: ";
  8.     cin>>score;
  9.     level=score/10;
  10.     switch(level)     //針對level做切換
  11.     {
  12.          case 10: case 9:
  13.               cout<<"優!"<<endl;
  14.               break;
  15.          case 8:
  16.               cout<<"甲!"<<endl;
  17.               break;
  18.          case 7:
  19.               cout<<"乙!"<<endl;
  20.               break;
  21.          case 6:
  22.               cout<<"丙!"<<endl;
  23.               break;
  24.          case 5: case 4: case 3: case 2: case 1: case 0:
  25.               cout<<"丁!"<<endl;
  26.               break;
  27.          default:
  28.               cout<<"輸入錯誤!"<<endl;
  29.     }
  30.     system("pause");
  31.     return 0;   
  32. }
複製代碼

返回列表