#include #include #include //for string #include using namespace std; //For example, 2024 = 12 * 168 + 8 //Therefore the value of the expression 2024 % 12 is 8 (the year of the dragon). //And since n is 12, the value of the expression 2024 % n is also 8. int main() { string animal[] { "monkey", // 0 "rooster", // 1 "dog", // 2 "pig", // 3 "rat", // 4 "ox", // 5 "tiger", // 6 "hare", // 7 "dragon", // 8 "snake", // 9 "horse", //10 "sheep" //11 }; int n {end(animal) - begin(animal)}; //number of elements in array cout << "Please type a year: "; int year {0}; cin >> year; if (!cin) { cerr << "Sorry, that wasn't a number.\n"; return EXIT_FAILURE; } if (year <= 0) { cerr << "Sorry, the year has to be a positive number.\n"; return EXIT_FAILURE; } time_t t {time(nullptr)}; tm *p {localtime(&t)}; int currentYear {p->tm_year + 1900}; //the current year if (year < currentYear) { cout << year << " was the year of the " << animal[year % n] << ".\n"; } else if (year == currentYear) { cout << year << " is the year of the " << animal[year % n] << ".\n"; } else { cout << year << " will be the year of the " << animal[year % n] << ".\n"; } return EXIT_SUCCESS; }