標題:
switch 判斷式
[打印本頁]
作者:
tonyh
時間:
2016-3-26 11:18
標題:
switch 判斷式
本帖最後由 tonyh 於 2018-6-20 17:06 編輯
利用 switch 判斷式, 設計一成績分級程式, 分級方式如下:
80分~100分 甲等
70分~79分 乙等
60分~69分 丙等
0分~59分 不及格
不在以上範圍 輸入錯誤
[使用者介面如下]
請輸入你的成績: 77
乙等!
請輸入你的成績: 101
輸入錯誤!
#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-3-26 11:53
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x;
re:
cout<<"請輸入你的成績: ";
cin>>x;
switch(x)
{
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-3-26 11:54
using namespace std;
int main()
{
int x;
cout<<"請輸入你的成績"<<endl;
cin>>x;
switch(x)
{
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-3-26 11:54
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
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;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
張孟軒
時間:
2016-3-26 11:55
#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;
}
複製代碼
作者:
陳泓瑜
時間:
2016-3-26 11:59
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int scr;
RE:
cout<<"請輸入你的成績: ";
cin>>scr;
switch(scr)
{
case 80 ... 100:
cout<<"甲等"<<endl;
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-4-9 09:55
#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-4-9 10: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