Board logo

標題: if...else if...else 判斷式 [打印本頁]

作者: tonyh    時間: 2018-7-11 15:39     標題: if...else if...else 判斷式

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {   
  6.     int score; //變數名稱與要做的事有一定程度的相關
  7.     re:
  8.     cout<<"請輸入你的成績: ";
  9.     cin>>score;
  10.     if(score==100) //在判斷兩邊的值是否相等,要用雙等號
  11.         cout<<"哇!滿分!"<<endl;
  12.     else if(score<100 && score>=60)
  13.         cout<<"恭喜你及格了,給你糖吃!"<<endl;
  14.     else if(score<60 && score>0)
  15.         cout<<"不及格!打屁股!"<<endl;
  16.     else if(score==0)
  17.         cout<<"零分?斬!"<<endl;
  18.     else
  19.         cout<<"輸入錯誤!斬!"<<endl;
  20.     goto re;
  21.     system("pause");
  22.     return 0;   
  23. }
複製代碼

作者: 古蕾娜    時間: 2018-7-11 15:59

本帖最後由 tonyh 於 2018-7-11 16:06 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {   
  6.     int score;
  7.     cout<<"please enter your scores: ";
  8.     cin>>score;
  9.     if (score==100)
  10.     cout<<"wow good job!"<<endl;
  11.     else if(score<100 && score>=60)
  12.     cout<<" congratulations you have passed:))"<<endl;
  13.      else if(score<60 && score>0)
  14.         cout<<"you have not passed:("<<endl;
  15.     else if(score==0)
  16.         cout<<"0, very bad!"<<endl;
  17.     else
  18.         cout<<"you have entered incorrect marks"<<endl;
  19.     system("pause");
  20.     return 0;   
  21. }
複製代碼

作者: 古昇暘    時間: 2018-7-11 16:04

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int score;
  7.     re:
  8.     cout<<"plese enter your score: ";
  9.     cin>>score;
  10.     if(score==100)
  11.         cout<<"awesome marks! I wish you were my homework buddy"<<endl;
  12.     else if(score<100 && score>60)
  13.         cout<<"nice work there buddy!"<<endl;
  14.     else if(score<60 && score>0)
  15.         cout<<"Maybe next time!"<<endl;
  16.     else
  17.         cout<<"Dont be a liar!"<<endl;
  18.     system("pause");
  19.     goto re;
  20.     return 0;   
  21. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2