本帖最後由 鄭繼威 於 2023-2-1 20:28 編輯
請設計一程式,
能根據使用者輸入的民國年,回報該年是哪個生肖。
"鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗","豬"
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int y; //民國年
- string n[]={"鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗","豬"};
- while(true)
- {
- cout<<"民國年: ";
- cin>>y;
- if(y%12==0)
- {
- //12的倍數是豬年
- cout<<"豬年!"<<endl<<endl;
- }
- else
- {
- //每12一輪
- cout<<n[y%12-1]<<"年!"<<endl<<endl;
- }
- }
- system("pause");
- return 0;
- }
複製代碼 |