標題:
[隨堂測驗] if...else if...else 判斷式
[打印本頁]
作者:
許婷芳
時間:
2019-8-9 17:51
標題:
[隨堂測驗] if...else if...else 判斷式
利用 if...else if...else 判斷式, 設計一成績分級程式, 分級方式如下:
90分~100分 優等
80分~89分 甲等
70分~79分 乙等
60分~69分 丙等
0分~59分 不及格
不在以上範圍 輸入錯誤
[使用者介面如下]
[attach]6949[/attach]
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
re:
cout<<"請輸入你的成績: ";
cin>>score;
if(score>100)
cout<<"輸入錯誤!”"<<endl;
else if(score<=100 && score>=90)
cout<<"優等!"<<endl;
else if(score<=89 && score>=80)
cout<<"甲等!”"<<endl;
else if(score<=79 && score>=70)
cout<<"乙等!"<<endl;
else if(score<=69 && score>=60)
cout<<"丙等!"<<endl;
else if(score<=59 || score>=0)
cout<<"不及格!"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
尤爾呈
時間:
2019-8-9 20:02
本帖最後由 尤爾呈 於 2019-8-9 20:18 編輯
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int score;
re:
cout<<"請輸入你的成績:";
cin>>score;
if(score>=60)
cout<<"恭喜你及格了,給你糖吃!"<<endl;
else
cout<<"不及格!打屁股!"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
尤爾呈
時間:
2019-8-9 20:39
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int score;
re:
cout<<"請輸入你的成績:";
cin>>score;
if(score==100)
cout<<"哇!滿分!"<<endl;
else if(score<100 && score>=60)
cout<<"恭喜你及格了,給你糖吃!"<<endl;
else if(score<60>0)
cout<<"不及格!打屁股!"<<endl;
else if(score==0)
cout<<"零分?斬!"<<endl;
else
cout<<"輸入錯誤!斬!"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
謝以愛
時間:
2019-8-9 20:53
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int score;
cout<<"請輸入你的成績:"<<endl;
cin>>score;
if(score<=100&&score>=90)
cout<<"優等"<<endl;
else if(score<90&&score>=80)
cout<<"甲等"<<endl;
else if(score<80&&score>=70)
cout<<"乙等"<<endl;
else if(score<70&&score>=60)
cout<<"丙等"<<endl;
else if(score<60&&score>=0)
cout<<"不及格"<<endl;
else
cout<<"輸入錯誤"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
謝以恩
時間:
2019-8-9 20:56
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score; //變數名稱與要做的事有一定程度的相關
re:
cout<<"請輸入你的成績: ";
cin>>score;
if(score==100&& score>=90) //在判斷兩邊的值是否相等,要用雙等號
cout<<"優等!"<<endl;
else if(score<=89 && score>=80)
cout<<"甲等"<<endl;
else if(score<=79 && score>=70)
cout<<"乙等!"<<endl;
else if(score<=69 && score>=60)
cout<<"丙等!"<<endl;
else if(score<=59 && score>=50)
cout<<"不及格!"<<endl;
else
cout<<"輸入錯誤!斬!"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
蘇詠翔
時間:
2019-8-9 20:57
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
re:
cout<<"請輸入你的成績:";
cin>>score;
if (score<=100 && score>=90)
cout<<"優等"<<endl;
else if (score<=89 && score>=80)
cout<<"甲等"<<endl;
else if (score<=79 && score>=70)
cout<<"乙等"<<endl;
else if (score<=69 && score>=60)
cout<<"丙等"<<endl;
else if (score<=59 && score>=0)
cout<<"不及格"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
尤爾呈
時間:
2019-8-9 21:04
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int score;
re:
cout<<"請輸入你的成績:";
cin>>score;
if(score>=90&&score<=100)
cout<<"優等!!"<<endl;
else if(score>=80&&score<=89)
cout<<"甲等"<<endl;
else if(score>=70&&score<=79)
cout<<"乙等"<<endl;
else if(score>=60&&score<=69)
cout<<"丙等"<<endl;
else if(score>=0&&score<=59)
cout<<"不及格"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
林祐霆
時間:
2019-8-9 21:04
本帖最後由 林祐霆 於 2019-8-9 21:19 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a;
re:
cout<<"請輸入你的考試成績。"<<endl;
cin>>a;
if(a==100)
cout<<"厲害厲害!佩服佩服!"<<endl;
else if(a<100&&a>89)
cout<<"你棒棒!"<<endl;
else if(a<=89&&a>=79)
cout<<"還不錯!"<<endl;
else if(a<=79&&a>=69)
cout<<"再加油!"<<endl;
else if(a>=60&&a<69)
cout<<"太弱囉!"<<endl;
else if(a>0&&a<60)
cout<<"太爛了!"<<endl;
else if(a==0)
cout<<"你完了!!!"<<endl;
else if(a<0 || a>=101)
cout<<"謊報成績,打死你!!!"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
洪承廷
時間:
2019-8-9 21:13
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int score;
re:
cout<<"請輸入你的成績:";
cin>>score;
if(score>=90&&score<=100)
cout<<"優等!!"<<endl;
else if(score>=80&&score<=89)
cout<<"甲等"<<endl;
else if(score>=70&&score<=79)
cout<<"乙等"<<endl;
else if(score>=60&&score<=69)
cout<<"丙等"<<endl;
else if(score>=0&&score<=59)
cout<<"不及格"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
廖文綺
時間:
2019-8-9 21:16
include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
re:
cout<<"請輸入你的成績: ";
cin>>score;
if (score<=100 && score >=90)
cout<<"優等!"<<endl;
else if(score<=89 && score>=80)
cout<<"甲等"<<endl;
else if(score<=79 && score>=70)
cout<<"乙等"<<endl;
else if(score<=69 && score>=60)
cout<<"丙等"<<endl;
else if(score<60 && score>=1)
cout<<"不及格!"<<endl;
else if(score==0)
cout<<"打屁股!"<<endl;
else
cout<<"輸入錯誤!斬"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
尤爾呈
時間:
2019-8-16 19:47
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int score;
cout<<"請輸入你的成績"<<endl;
re:
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:
case 101...500
cout<<"輸入錯誤"<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2