標題:
switch 判斷式
[打印本頁]
作者:
tonyh
時間:
2014-9-13 11:26
標題:
switch 判斷式
本帖最後由 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;
}
複製代碼
作者:
洪振庭
時間:
2014-9-13 11:34
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int score;
int 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:
cout<<"丁"<<endl;
break;
case 4:
case 3:
case 2:
case 1:
case 0:
cout<<"不及格"<<endl;
break;
default:
cout<<"錯誤"<<endl;
break;
}
system("pause");
return 0;
}
複製代碼
作者:
李知易
時間:
2014-9-13 11:39
本帖最後由 李知易 於 2015-9-5 12:14 編輯
//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;
}
複製代碼
作者:
李大全
時間:
2014-9-13 11:41
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;
}
複製代碼
作者:
梁和雋
時間:
2014-9-13 11:45
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int a,b;
cout<<"請輸入成績";
cin>>a;
a=b/10;
switch(b)
{
case 10:
case 9:
case 8:
cout<<"甲";
break;
case 7:
cout<<"乙";
break;
case 6:
cout<<"丙";
break;
case 5:
case 4:
case 3:
case 2:
case 1:
cout<<"不及格";
break;
default:
for(int a=1;a>0;a++)
cout<<"\a";
}
system("pause");
return 0;
}
複製代碼
作者:
謝瀞儀
時間:
2014-9-13 11:45
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score,level;
cout<<"Please type in your score: ";
cin>>score;
level=score/10;
switch(level)
{
case 10:
case 9:
cout<<"A!"<<endl;
break;
case 8:
cout<<"B!"<<endl;
break;
case 7:
cout<<"C!"<<endl;
break;
case 6:
cout<<"D!"<<endl;
break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:
cout<<"Your got failed!"<<endl;
break;
default:
cout<<"輸入錯誤!"<<endl;
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2