返回列表 發帖

[隨堂測驗] 生肖判斷

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





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

  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. }
複製代碼

TOP

  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. }
複製代碼

TOP

  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. }
複製代碼

TOP

  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. }
複製代碼

TOP

  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. }
複製代碼

TOP

返回列表