#include #include using namespace std; const int date_length[] = { 0, //dummy element so that January will have subscript 1 31, //January 28, //February 31, //March 30, //April 31, //May 30, //June 31, //July 31, //August 30, //September 31, //October 30, //November 31 //December }; struct date { int year; int month; //1 to 12 inclusive int day; //1 to date_length[month] inclusive }; //Version 3 will need this semicolon, too. void next(date *p, int count); void next(date *p); void print(const date *p); int main() { date d = {2014, 1, 1}; //curly braces around initial values cout << "How many days forward from "; print(&d); cout << " do you want to go? "; int count; //uninitialized variable cin >> count; next(&d, count); cout << "The new date is "; print(&d); cout << ".\n"; return EXIT_SUCCESS; } void next(date *p, int count) { //Call the one-argument next (line 59) count times. //Pass along the pointer we received. while (--count >= 0) { next(p); } } void next(date *p) { //Move to the next date. if (++p->day > date_length[p->month]) { p->day = 1; if (++p->month > 12) { p->month = 1; ++p->year; } } } void print(const date *p) { //cout << (*p).month << "/" << (*p).day << "/" << (*p).year; cout << p->month << "/" << p->day << "/" << p->year; }