#include #include #include //for the functions time and localtime using namespace std; int main() { //Get the current hour of the day (0 to 23 inclusive). time_t t {time(nullptr)}; tm *p {localtime(&t)}; int hour {p->tm_hour}; // if (hour >= 12) { // if (hour < 12 + 9) { // if (hour < 12 + 5) { // cout << "Good afternoon."; // } else { // cout << "Good evening."; // } // } else { // cout << "Good night."; // } // } else { // cout << "Good morning."; // } if (hour >= 21) { // same as 12 + 9 (or 9 pm) cout << "Good night."; } else if (hour >= 17) { // same as 12 + 5 (or 5 pm) cout << "Good evening."; } else if (hour >= 12) { // 12 pm cout << "Good afternoon."; } else { // anytime before noon cout << "Good morning."; } cout << "\n"; return EXIT_SUCCESS; }