標題:
switch 判斷式 (二)
[打印本頁]
作者:
王瑞喻
時間:
2020-7-27 20:24
標題:
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;
}
複製代碼
作者:
邱玟瑜
時間:
2020-7-29 14:27
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
int score;
cout<<"請輸入你的成績:"<<endl;
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;
case 0 ... 59:
cout<<"不及格"<<endl;
default:
cout<<"輸入錯誤"<<endl;
}
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
樂柏謙
時間:
2020-7-29 14:27
#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;
}
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
鄭軒濬
時間:
2020-7-29 14:28
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int avocado;
cout<<"請輸入你的成績:";
cin>>avocado;
switch(avocado)
{
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;
}
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
陳柏恩
時間:
2020-7-29 14: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;
}
複製代碼
作者:
周秉融
時間:
2020-7-29 14: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;
}
複製代碼
作者:
林秉軒
時間:
2020-7-29 14:28
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int X;
cout<<"請輸入成績";
cin>>X;
switch(X)
{
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 ;
}
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
何郡毓
時間:
2020-7-29 14: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;
}
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
王晏璿
時間:
2020-7-29 14: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;
}
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
黃韋誌
時間:
2020-7-29 14:32
#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;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2