本帖最後由 tonyh 於 2014-9-13 11:36 編輯
利用 switch 判斷式, 設計一成績分級程式, 分級方式如下:
80分~100分 甲等
70分~79分 乙等
60分~69分 丙等
0分~59分 不及格
不在以上範圍 輸入錯誤
[使用者介面如下]
請輸入你的成績: 77
乙等!
請輸入你的成績: 101
輸入錯誤!- //switch...case
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int score,level;
- cout<<"請輸入你的成績: ";
- cin>>score;
- level=score/10;
- switch(level)
- {
- case 10:
- case 9:
- case 8:
- cout<<"甲等!"<<endl;
- break;
- case 7:
- cout<<"乙等!"<<endl;
- break;
- case 6:
- cout<<"丙等!"<<endl;
- break;
- case 5:
- case 4:
- case 3:
- case 2:
- case 1:
- case 0:
- cout<<"不及格!"<<endl;
- break;
- default:
- cout<<"輸入錯誤!"<<endl;
- }
- system("pause");
- return 0;
- }
複製代碼 |