標題:
switch 判斷式
[打印本頁]
作者:
tonyh
時間:
2018-7-11 16:12
標題:
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;
}
複製代碼
作者:
古蕾娜
時間:
2018-7-11 16:27
本帖最後由 古蕾娜 於 2018-7-11 16:29 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
cout<<"please enter your score: ";
cin>>score;
switch(score)
{
case 80 ... 100:
cout<<"A"<<endl;
case 70 ... 79:
cout<<"B"<<endl;
case 60 ... 69:
cout<<"C"<<endl;
case 0 ... 59:
cout<<"D"<<endl;
default:
cout<<"you have entered wrong"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
古昇暘
時間:
2018-7-11 16:34
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
cout<<"plese enter your score: ";
cin>>score;
switch(score)
{
case 80 ... 100:
cout<<"A+-A"<<endl;
break;
case 70 ... 79:
cout<<"B+-B"<<endl;
break;
case 60 ... 69:
cout<<"C+-C"<<endl;
break;
case 0 ... 59:
cout<<"D-F"<<endl;
break;
default:
cout<<"Incorrect"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
古昇暘
時間:
2018-7-12 12:39
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
cout<<"Please enter your age: ";
cin>>score;
switch(score)
{
case 0 ... 3:
cout<<"Free entry!"<<endl;
break;
case 4 ... 12:
cout<<"Half-ticket 50$"<<endl;
break;
case 13 ... 64:
cout<<"Full ticket 100$"<<endl;
break;
case 65 ... 100:
cout<<"elderly ticket 70$"<<endl;
break;
default:
cout<<"Your not human and we only accept humans here sorry!"<<endl;
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2