#include #include using namespace std; bool is_leap(int year); int main() { int month, day, year; //uninitialized variables cout << "Enter month (1 to 12), day (1 to 31), year (1 up).\n" << "Press RETURN after each number.\n"; if (!(cin >> month >> day >> year)) { cerr << "input failed\n"; return EXIT_FAILURE; } //Distance from January 1, 1 AD to the date the user input. //For example, if the user input January 1, 1 AD, //then distance would be zero. int distance = day - 1; for (int y = 1; y < year; ++y) { distance += 365; //means distance = distance + 365; if (is_leap(y)) { ++distance; } if (y == 1752) { distance -= 11; //Missing September 3 to 13 inclusive. } } const int length[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; for (int m = 1; m < month; ++m) { if (m == 2 && is_leap(year)) { distance += 29; } else { distance += length[m]; } } const string name[] = { "Satur", //January 1, 1 AD was a Saturday. "Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri" }; cout << name[distance % 7] << "day " << month << "/" << day << "/" << year << "\n"; return EXIT_SUCCESS; } bool is_leap(int year) { if (year <= 1752) { return year % 4 == 0; //Julian calendar before Gregorian } if (year % 400 == 0) { return true; //1600 and 2000 were leap years. } if (year % 100 == 0) { return false; //1700 and 1800 were not leap years. } return year % 4 == 0; }