標題:
switch 判斷式
[打印本頁]
作者:
王瑞喻
時間:
2019-6-7 23:35
標題:
switch 判斷式
本帖最後由 tonyh 於 2019-8-19 22:08 編輯
利用 switch 判斷式, 設計一成績分級程式, 分級方式如下:
80分~100分 甲等
70分~79分 乙等
60分~69分 丙等
0分~59分 不及格
不在以上範圍 輸入錯誤
[使用者介面如下]
請輸入你的成績: 77
乙等!
請輸入你的成績: 101
輸入錯誤!
#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;
}
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
劉愷恩
時間:
2019-6-15 11:37
#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;
}
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
王翎璇
時間:
2019-6-15 11:43
#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;
}
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
曾宥程
時間:
2019-6-15 11:43
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int score;
cout<<"請輸入你的成績: ";
cin>>score;
switch(score)
{
case 80 ... 100:
cout<<"A++"<<endl;
break;
case 70 ... 79:
cout<<"B++"<<endl;
break;
case 60 ... 69:
cout<<"C++"<<endl;
break;
case 0 ... 59:
cout<<"F--"<<endl;
break;
default:
cout<<"別鬧了"<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
蔡少宇
時間:
2019-6-15 11:45
#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;
}
cout<<endl;
goto re:
system("pause")
return 0;
}
複製代碼
作者:
鄭羽捷
時間:
2019-6-15 11:47
#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;
}
cout<<endl;
goto re;
system("pause");
return 0;
}
}
複製代碼
作者:
林孟蓁
時間:
2019-6-15 11:50
#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;
}
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
郭哲維
時間:
2019-6-15 11:53
本帖最後由 郭哲維 於 2019-6-15 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;
}
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
駱顗安
時間:
2020-4-23 16:15
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
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;
default:
cout<<"輸入錯誤!"<<endl;
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2