標題:
switch 判斷式
[打印本頁]
作者:
tonyh
時間:
2016-5-23 11:58
標題:
switch 判斷式
本帖最後由 tonyh 於 2016-5-23 12:23 編輯
利用 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;
}
複製代碼
作者:
邱柏揚
時間:
2016-5-23 12:29
本帖最後由 邱柏揚 於 2016-5-24 09:38 編輯
#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;
}
複製代碼
作者:
張恩嘉
時間:
2016-5-23 12:31
本帖最後由 張恩嘉 於 2016-5-24 10:04 編輯
#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-5-23 12:31
本帖最後由 謝易錚 於 2016-5-24 09:59 編輯
#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;
}
複製代碼
作者:
王淳暘
時間:
2016-5-23 12:31
本帖最後由 王淳暘 於 2016-5-24 09:38 編輯
#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-5-23 12:31
本帖最後由 蔡孟庭 於 2016-5-24 10:02 編輯
#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-5-23 12:32
本帖最後由 劉得榮 於 2016-5-23 21:05 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
cout<<"請輸入你的成績:";
while(cin>>score)
{
switch(score)
{
case 80 ... 100:
cout<<"甲等!";
break;
case 70 ... 79:
cout<<"乙等";
break;
case 60 ... 69:
cout<<"丙等";
break;
case 0 ... 59:
cout<<"不及格";
break;
default:
cout<<"錯誤";
}
cout<<endl;
cout<<"請輸入你的成績:";
}
return 0;
}
複製代碼
作者:
劉純妘
時間:
2016-5-23 12:32
本帖最後由 劉純妘 於 2016-5-24 10:02 編輯
#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;
default:
cout<<"輸入錯誤"<<endl;
}
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
邱士杰
時間:
2016-5-23 12:32
#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-5-23 12:32
#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;
}
複製代碼
作者:
劉瑑恩
時間:
2016-5-23 12:33
#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-5-23 12:33
本帖最後由 孫漢瑄 於 2016-5-24 10:00 編輯
#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-5-23 12:34
本帖最後由 洪為濬 於 2016-5-24 10:13 編輯
#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;
複製代碼
作者:
謝旻錡
時間:
2016-5-24 09:41
本帖最後由 謝旻錡 於 2016-5-24 09:59 編輯
#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;
break;
}
system("pause");
return 0;
}
複製代碼
作者:
蔡孟君
時間:
2016-5-24 10:02
#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;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2