標題:
switch 判斷式
[打印本頁]
作者:
陳品肇
時間:
2019-4-11 14:31
標題:
switch 判斷式
利用 switch 判斷式, 設計一成績分級程式, 分級方式如下:
80分~100分 甲等
70分~79分 乙等
60分~69分 丙等
0分~59分 不及格
不在以上範圍 輸入錯誤
[使用者介面如下]
請輸入你的成績: 77
乙等!
請輸入你的成績: 101
輸入錯誤!
#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;
}
複製代碼
作者:
洪藜芸
時間:
2019-4-13 11:34
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a;
cout<<"請輸入成績:";
cin>>a;
switch(a)
{
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;
}
複製代碼
作者:
李易展
時間:
2019-4-13 11:37
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int a;
cout<<"請輸入你的成績: ";
cin>>a;
switch(a)
{
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;
}
複製代碼
作者:
謝蓮金
時間:
2019-4-13 11:38
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a;
cout<<"請輸入你的成績: ";
cin>>a;
switch(a)
{
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;
break;
}
system("pause");
return 0;
}
複製代碼
作者:
黃傳耀
時間:
2019-4-13 11:39
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int score;
cout<<"請輸入分數:";
cin>>score;
switch(score)
{
case 80 ... 100:
cout<<"甲等,非常好"<<endl;
break;
case 79 ... 70:
cout<<"乙等,再加油"<<endl;
break;
case 60 ... 69:
cout<<"丙等,很危險"<<endl;
break;
case 0 ... 59:
cout<<"不及格,去參加補救教學"<<endl;
break;
default:
cout<<"輸入錯誤"<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
邱楷宸
時間:
2019-4-13 11:39
#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<<"不及格D:"<<endl;
break;
default:
cout<<"輸入錯誤:P"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
王建葦
時間:
2019-4-20 10:02
#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;
break;
}
system("pause");
return 0;
}
複製代碼
作者:
洪子涵
時間:
2019-4-27 12:00
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int g;
cout<<"請輸入你的成績: ";
cin>>g;
switch(g)
{
case 0 ... 59 :
{
cout<<"不及格"<<endl;
break;
}
case 60 ... 69 :
{
cout<<"丙等"<<endl;
break;
}
case 70 ... 79 :
{
cout<<"乙等"<<endl;
break;
}
case 80 ... 100 :
{
cout<<"甲等"<<endl;
break;
}
default :
cout<<"輸入錯誤"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
邱楷宸
時間:
2019-5-3 19:26
#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;
}
複製代碼
作者:
陳宇柏
時間:
2019-5-28 18:07
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
re:
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;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2