標題:
switch 判斷式
[打印本頁]
作者:
陳品肇
時間:
2018-10-27 14:26
標題:
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-10-27 14:54
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a;
start:
cout<<"請輸入成績:";
cin>>a;
switch(a)
{
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;
break;
}
goto start;
system("pause");
return 0;
}
複製代碼
回復
1#
陳品肇
作者:
吳孟修
時間:
2018-10-27 14:55
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
a:
int x;
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 a;
system("pause");
return 0;
}
複製代碼
作者:
吳孟書
時間:
2018-10-27 15:05
#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<<"輸入錯誤(error)"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
曲書辰
時間:
2018-10-27 15:06
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int X;
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;
break;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
周孫印
時間:
2018-10-27 15:08
#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-10-27 15:11
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
jeb:
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;
}
goto jeb;
system("pause");
return 0;
}
複製代碼
作者:
王瑞喻
時間:
2018-10-27 15:23
#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-11-3 12:46
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
re:
cout<<"請輸入你的成績: ";
cin>>score;
switch(score)
{
case 80 ... 100:
cout<<"甲等\n\n";
break;
case 70 ... 79:
cout<<"乙等\n\n";
break;
case 60 ... 69:
cout<<"丙等\n\n";
break;
case 0 ... 59:
cout<<"不及格\n\n";
break;
default:
cout<<"輸入錯誤\n\n";
}goto re;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2