標題:
switch 判斷式
[打印本頁]
作者:
tonyh
時間:
2016-10-1 13:56
標題:
switch 判斷式
本帖最後由 tonyh 於 2019-8-19 22:36 編輯
利用 switch 判斷式, 設計一成績分級程式, 分級方式如下:
80分~100分 甲等
70分~79分 乙等
60分~69分 丙等
0分~59分 不及格
不在以上範圍 輸入錯誤
[使用者介面如下]
請輸入你的成績: 77
乙等!
請輸入你的成績: 101
輸入錯誤!
[attach]6985[/attach]
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
cout<<"請輸入你的成績: ";
cin>>score;
switch(score)
{
case 80 ... 100:
cout<<"甲等"<<endl;
break;
case 70 ... 79:
cout<<"乙等"<<endl;
break;
case 60 ... 69:
cout<<"丙等"<<endl;
break;
case 0 ... 59:
cout<<"不及格"<<endl;
break;
default:
cout<<"輸入錯誤"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
黃宥鈞
時間:
2016-10-1 14:29
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
cout<<"請輸入你的成績:";
cin>>score;
switch(score)
{
case 80 ... 100:
cout<<"甲等!"<<endl;
break;
case 70 ... 79:
cout<<"甲等!"<<endl;
break;
case 60 ... 69:
cout<<"丙等!"<<endl;
break;
case 0 ... 59:
cout<<"不及格!"<<endl;
break;
default:
cout<<"輸入錯誤!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
曾彥翔
時間:
2016-10-1 14:39
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
cout<<"請輸入你的成績: "<<endl;
cin>>score;
switch(score)
{
case 80 ... 100:
cout<<"甲等!"<<endl;
break;
case 70 ... 79:
cout<<"乙等!"<<endl;
break;
case 60 ... 69:
cout<<"丙等!"<<endl;
break;
case 0 ... 59:
cout<<"不及格!"<<endl;
break;
default:
cout<<"error!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
吳晉榕
時間:
2016-10-1 14:41
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
cout<<"請輸入你的成績: ";
cin>>score;
switch (score)
{
case 80...100:
cout<<"甲等"<<endl;
break;
case 79...70:
cout<<"乙等"<<endl;
break;
case 69...60:
cout<<"丙等"<<endl;
break;
default:
cout<<"輸出入錯誤"<<endl;
break;
system("pause");
return 0;
}
複製代碼
作者:
許紘誌
時間:
2016-10-1 14:44
本帖最後由 許紘誌 於 2016-10-1 15:15 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int score;
cout<<"請輸入你的成績:";
cin>>score;
switch(score)
{
case 80 ... 100:
cout<<"甲等!"<<endl;
break;
case 70 ... 79:
cout<<"乙等!"<<endl;
break;
case 60 ... 69:
cout<<"丙等!"<<endl;
break;
case 0 ... 59:
cout<<"不及格!"<<endl;
break;
default:
cout<<"輸入錯誤!"<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
譚暐霖
時間:
2016-10-1 14:45
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
re:
cout<<"請輸入你的成績: "<<endl;
cin>>score;
switch (score)
{
case 80 ... 100:
cout<<"甲!!!"<<endl;
break;
case 70 ... 79:
cout<<"已!!!"<<endl;
break;
case 60 ... 69:
cout<<"丙"<<endl;
break;
case 0 ... 59 :
cout<<"不及格!!!"<<endl;
break;
default:
cout<<"輸入錯誤!!!"<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
朱聿謙
時間:
2016-10-1 14:48
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
cout<<"請輸入你的成績:";
cin>>score;
switch(score)
{
case 80 ... 100:
cout<<"甲等"<<endl;
break;
case 70 ... 79:
cout<<"乙等"<<endl;
break;
case 60 ... 69:
cout<<"丙等"<<endl;
break;
case 0 ... 59:
cout<<"不及格"<<endl;
break;
default:
cout<<"輸入錯誤"<<endl;
}
system("pause");
return 0 ;
}
複製代碼
作者:
蔡幸融
時間:
2016-10-1 14:50
本帖最後由 蔡幸融 於 2016-10-1 15:16 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
cout<<"請輸入你的成績: "<<endl;
cin>>score;
switch(score)
{
case 80 ... 100:
cout<<"甲等!"<<endl;
break;
case 70 ... 79:
cout<<"乙等!"<<endl;
break;
case 60 ... 69:
cout<<"丙等!"<<endl;
break;
case 0 ... 59:
cout<<"不及格!"<<endl;
break;
default:
cout<<"輸入錯誤!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
洪榜蔓
時間:
2016-10-1 14:53
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
cout<<"請輸入你的成績:";
cin>>score;
switch(score)
{
case 80 ... 100:
cout<<"甲等"<<endl;
break;
case 70 ... 79:
cout<<"乙等"<<endl;
break;
case 60 ... 69:
cout<<"丙等"<<endl;
break;
case 0 ... 59:
cout<<"不及格!"<<endl;
break;
default:
cout<<"喂!別亂輸入!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
蕭澧邦
時間:
2016-10-1 14:55
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
cout<<"請輸入您的分數: ";
cin>>score;
switch(score)
{
case 80 ... 100:
cout<<"甲等"<<endl;
break;
case 70 ... 79:
cout<<"乙等"<<endl;
break;
case 60 ... 69:
cout<<"丙等"<<endl;
break;
case 0 ... 59:
cout<<"不及格"<<endl;
break;
default:
cout<<"輸入錯誤"<<endl;
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2