標題:
switch判斷式 (一)
[打印本頁]
作者:
tonyh
時間:
2019-8-16 19:44
標題:
switch判斷式 (一)
利用 switch 判斷式,設計一成績分級程式, 分級方式如下:
90分~100分 優等
80分~89分 甲等
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 90 ... 100:
cout<<"優等"<<endl;
break;
case 80 ... 89:
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-8-16 20:18
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
re:
cout<<"請輸入你的成績: ";
cin>>score;
switch(score)
{
case 90 ... 100:
cout<<"優等"<<endl;
break;
case 80 ... 89:
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-8-16 20:20
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
re:
cout<<"請輸入你的成績: ";
cin>>score;
switch(score)
{
case 90 ... 100:
cout<<"優等"<<endl;
break;
case 80 ... 89:
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-8-16 20:21
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int s;
re:
cout<<"請輸入你的成績: ";
cin>>s;
switch(s)
{
case 90 ... 100:
cout<<"優等!"<<endl;
break;
case 80 ... 89:
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-8-16 20:23
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
re:
cout<<"請輸入你的成績:";
cin>>score;
switch(score)
{
case 90 ... 100:
cout<<"優等"<<endl;
break;
case 80 ... 89:
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-8-16 20:24
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int s;
asdg:
cout<<"輸入成績";
cin>>s;
switch(s)
{
case 90 ... 100:
cout<<"優等"<<endl;
break;
case 80 ... 89:
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 asdg;
}
goto asdg;
system("pause");
return 0;
}
複製代碼
作者:
蔡忻霓
時間:
2019-8-16 20:24
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
cout<<"請輸入你的成績: ";
cin>>score;
switch(score)
{
case 90 ... 100:
cout<<"優等!"<<endl;
break;
case 80 ... 89:
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-8-16 20:25
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int s;
re:
cout<<"輸入你的成績:";
cin>>s;
switch(s)
{
case 90 ... 100:
cout<<"優"<<endl;
break;
case 80 ... 89:
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-8-16 20:25
#include<iostream>
#include<cstdlib>
using namespace std;
int main ()
{
int score;
i:
cout<<"請輸入你的成績 :";
cin>>score;
switch(score)
{
case 90 ... 100:
cout<<"優等"<<endl;
break;
case 80 ... 89:
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 i;
system("pause");
return 0;
}
複製代碼
作者:
楊佑諺
時間:
2019-8-16 20:25
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
re:
cout<<"請輸入你的成績: ";
cin>>score;
switch(score)
{
case 90 ... 100:
cout<<"優等"<<endl;
break;
case 80 ... 89:
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-8-16 20:28
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
cout<<"請輸入你的成績: ";
cin>>score;
switch(score)
{
case 90 ... 100:
cout<<"優等"<<endl;
break;
case 80 ... 89:
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-8-16 20:30
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
cout<<"請輸入你的成績: ";
cin>>score;
switch(score)
{
case 90 ... 100:
cout<<"優等"<<endl;
break;
case 80 ... 89:
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-8-16 20:47
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int answer;
cout<<"請問你有幾個腦: (1)1顆,(2)2顆,(3)3顆,(4)4顆";
cin>>answer;
switch(ansewr)
{
case 1 :
cout<<"沒常識!"<<endl;
break;
case 2:
cout<<"答對了!"<<endl;
break;
case 3:
cout<<"天生的蠢才!"<<endl;
break;
case 4:
cout<<"有怪獸!"<<endl;
break;
default:
cout<<"輸入錯誤"<<endl;
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2