#include #include #include // for string #include // for time functions 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 {sizeof animal / sizeof animal[0]}; // number of elements in array // Get the current year time_t t {time(nullptr)}; tm *p {localtime(&t)}; int currentYear {p->tm_year + 1900}; 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; } string verb; if (year < currentYear) { verb = "was"; } else if (year == currentYear) { verb = "is"; } else { verb = "will be"; } cout << year << " " << verb << " the year of the " << animal[year % n] << ".\n"; return EXIT_SUCCESS; }