標題:
if...else if...else 判斷式
[打印本頁]
作者:
tonyh
時間:
2016-9-24 14:20
標題:
if...else if...else 判斷式
本帖最後由 tonyh 於 2019-5-18 11:41 編輯
關係運算
== 等於
< 小於
> 大於
<= 小於或等於
>= 大於或等於
!= 不等於
邏輯運算
&& and
|| or
#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>=60)
cout<<"恭喜你及格了,給你糖吃!"<<endl;
else if(score<60 && score>0)
cout<<"不及格!打屁股!"<<endl;
else if(score==0)
cout<<"零分?斬!"<<endl;
else
cout<<"輸入錯誤!斬!"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
黃宥鈞
時間:
2016-9-24 14:54
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
float score;
re:
cout<<"請輸入你的成績:";
cin>>score;
if(score==100)
{
cout<<"滿分!好棒棒!"<<endl;
}else if(score<100&&score>=60)
{
cout<<"及格!!"<<endl;
}
else if(score<60&&score>0)
{
cout<<"不及格!!!"<<endl;
}
else if(score==0)
{
cout<<"零分?斬!"<<endl;
}else
{
cout<<"輸入錯誤!驅逐出境!"<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
吳晉榕
時間:
2016-9-24 14:54
#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>=60)
cout<<"你及格"<<endl;
else if(score<60 && score>0)
cout<<"不及格"<<endl;
else if(score==0)
cout<<"鴨蛋??"<<endl;
else
cout<<"輸入錯誤"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
譚暐霖
時間:
2016-9-24 14:56
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
float score;
re:
cout<<"請輸入你的成績: "<<endl;
cin>>score;
if(score==100)
cout<<"及格!!!"<<endl;
else if(score<100 && score>=60)
cout<<"及格!!!"<<endl;
else if(score<60 && score>0)
cout<<"不及格"<<endl;
else if(score == 0)
cout<<"不及格!!!"<<endl;
else
cout<<"輸入錯誤!!!"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
曾彥翔
時間:
2016-9-24 14:57
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
float score;
cout<<"請輸入你的成績: "<<endl;
cin>>score;
if(score==100)
{
cout<<"滿分!"<<endl;
}else if(score>=60 && score<=100)
{
cout<<"恭喜你,及格!"<<endl;
}else if(score<=60 && score>0)
{
cout<<"不及格!"<<endl;
}else if(score==0)
{
cout<<"零分!"<<endl;
}else
{
cout<<"error!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
朱聿謙
時間:
2016-9-24 14:58
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
float score;
cout<<"請輸入你的成績:";
cin>>score;
if(score==100)
{
cout<<"滿分"<<endl;
}
else if(score<100 && score>=60)
{
cout<<"及格"<<endl;
}
else if(score<60 && score>0)
{
cout<<"不及格"<<endl;
}
else if(score==0)
{
cout<<"爛"<<endl;
}
else
{
cout<<"輸入錯誤"<<endl;
}
system ("pause");
return 0 ;
}
複製代碼
作者:
許紘誌
時間:
2016-9-24 15:00
#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>=60)
cout<<"恭喜你及格了!"<<endl;
else if(score<60 && score>0)
cout<<"你慘了!拖出去斬了!"<<endl;
else if(score==0)
cout<<"你死定了!烤了"<<endl;
else
cout<<"亂打!拖出去砍了"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
蔡幸融
時間:
2016-9-24 15:00
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
cout<<"請輸入你的成績: "<<endl;
cin>>score;
if(score==100)
{
cout<<"恭喜你滿分了!"<<endl;
}else if(score<100 && score>=60)
{
cout<<"恭喜你及格了!"<<endl;
}else if(score<60 && score>0)
{
cout<<"恭喜你沒及格"<<endl;
}else if(score==0)
{
cout<<"恭喜你鴨蛋"<<endl;
}else
{
cout<<"輸入錯誤"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
洪榜蔓
時間:
2016-9-24 15:08
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
float score;
cout<<"請輸入你的成績:";
cin>>score;
if(score==100)
{
cout<<"你竟然滿分!?粉棒帶你去吃大餐\"<<endl;
}
else if(score<100 && score>=60)
cout<<"很好有及格!ˊˇˋ"<<endl;
else if(score<60&& score>0)
cout<<"你又不及格了!?一個月不能吃零食"<<endl;
else if(score==0)
cout<<"你...你不及格就算了!還零分!?來人阿!把他拖出去給斬了"<<endl;
else
{
cout<<"你別亂輸入!!!!打你喔ˋˊ"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
吳晉榕
時間:
2016-9-24 15:09
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
re:
cout<<"請輸入你的成績: ";
cin>>score;
if(score<80&& score>=100)
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;
else
cout<<"輸入錯誤"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2