標題:
if...else if...else 判斷式
[打印本頁]
作者:
tonyh
時間:
2018-7-11 15:39
標題:
if...else if...else 判斷式
#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;
}
複製代碼
作者:
古蕾娜
時間:
2018-7-11 15:59
本帖最後由 tonyh 於 2018-7-11 16:06 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
cout<<"please enter your scores: ";
cin>>score;
if (score==100)
cout<<"wow good job!"<<endl;
else if(score<100 && score>=60)
cout<<" congratulations you have passed:))"<<endl;
else if(score<60 && score>0)
cout<<"you have not passed:("<<endl;
else if(score==0)
cout<<"0, very bad!"<<endl;
else
cout<<"you have entered incorrect marks"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
古昇暘
時間:
2018-7-11 16:04
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int score;
re:
cout<<"plese enter your score: ";
cin>>score;
if(score==100)
cout<<"awesome marks! I wish you were my homework buddy"<<endl;
else if(score<100 && score>60)
cout<<"nice work there buddy!"<<endl;
else if(score<60 && score>0)
cout<<"Maybe next time!"<<endl;
else
cout<<"Dont be a liar!"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2