#include #include #include //for class system_clock #include //for the function localtime using namespace std; void travel(int& hour, int& mins, int& sec, int distance); int main() { const auto now {chrono::system_clock::now()}; const time_t t {chrono::system_clock::to_time_t(now)}; const tm *const p {localtime(&t)}; //Get the current year, month, and day of the month. int h {p->tm_hour}; int m {p->tm_min}; //in the range 1 to 12 inclusive int s {p->tm_sec}; //in the range 1 to 31 inclusive cout << "How many seconds forward do you want to go from " << h << ":" << m << ":" << s << "? "; int distance {0}; cin >> distance; if (!cin) { cerr << "Sorry, that wasn't a number.\n"; return EXIT_FAILURE; } if (distance < 0) { cerr << "Distance " << distance << " can't be negative.\n"; return EXIT_FAILURE; } //The following statement can change the value of m, d, y, //but not the value of distance. travel(m, s, h, distance); cout << "The new time is: " << h << ":" << m << ":" << s << "\n"; return EXIT_SUCCESS; } //Move the date distance days into the future. void travel(int& mins, int& sec, int& hour, int distance) { /* Walk distance days into the future. Each iteration of the loop advances 1 day into the future. Each ++day, ++month, ++year will now change the value of an actual argument up in main. */ for (int i {0}; i < distance; ++i) { ++sec; if (sec >= 60) { sec = 0; ++mins; } if (mins >= 60){ mins = 0; ++hour; //Advance into a new month. } } }