#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}; cout << "On a 24-hour clock, the current hour is " << hour << ".\n"; cout << "On a 12-hour clock, the current hour is "; if (hour == 0) { cout << 12; //midnight } else if (hour <= 12) { cout << hour; //morning and noon } else { cout << hour - 12; //the rest of the day } cout << " "; //space between hour and latin abbreviation if (hour < 12) { cout << "a.m."; //ante meridiem } else { cout << "p.m."; //post meridiem } cout << "\n"; return EXIT_SUCCESS; }