Board logo

標題: [隨堂測驗] 生肖判斷 [打印本頁]

作者: 方浩葦    時間: 2024-8-3 03:33     標題: [隨堂測驗] 生肖判斷

請設計一程式,
能根據使用者輸入的西元年,回報該年是哪個生肖。





本帖隱藏的內容需要回復才可以瀏覽

作者: 林少謙    時間: 2024-8-3 16:21

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int x;
  8.     re:
  9.     cout<<"請輸入出生之西元年: ";
  10.     cin>>x;
  11.     x=x-1911;
  12.     x=x%12;
  13.     string a[]{"鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗","豬"};
  14.     cout<<endl<<a[x-1]<<"年!"<<endl<<endl;
  15.     goto re;
  16. }
複製代碼

作者: 李唯銘    時間: 2024-8-10 15:44

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int x;
  8.     re:
  9.     cout<<"請輸入出生之西元年: ";
  10.     cin>>x;
  11.     x=x-1911;
  12.     x=x%12;
  13.     string a[]{"鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗","豬"};
  14.     cout<<endl<<a[x-1]<<"年!"<<endl<<endl;
  15.     goto re;
  16. }
複製代碼

作者: 劉奕劭    時間: 2024-8-10 16:16

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int t;
  8.     cout<<"請輸入出生西元年: ";
  9.     cin>>t;
  10.     t=t-1911;

  11.     t=t%12;
  12.     string a[]{"鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗","豬"};
  13.     cout<<endl<<a[t-1]<<"年"<<endl<<endl;




  14.     system("pause");

  15.     return 0;

  16. }
複製代碼

作者: 洪榮辰    時間: 2024-8-11 17:20

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int x;
  8.     re:
  9.     cout<<"請輸入西元年: ";
  10.     cin>>x;
  11.     x=x-1911;
  12.     x=x%12;
  13.     string a[]{"鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗","豬"};
  14.     cout<<endl<<a[x-1]<<"年!"<<endl<<endl;
  15.     goto re;
  16. }
複製代碼

作者: 陳妍蓁    時間: 2024-8-16 22:00

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     srand(time(NULL));
  8.     int y;
  9. re:
  10.     cout<<"請輸入西元年:"<<endl;
  11.     cin>>y;
  12.     y=y-1911;
  13.     y=y%12;
  14.     string n[]={"鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗","豬"};
  15.     cout<<n[y-1]<<"年"<<endl;

  16.     system("pause");
  17.     goto re;
  18.     return 0;
  19. }
複製代碼





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