1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
//Using zeller's algorithm
//F=K+((13*M+1)/5)+D+(D/4)+(C/4)-2*C --- Formula
//(F=Day of week), (K=Day of month), (D=Last two digits of year),
//(C=first two digits of year(century)
#include <iomanip>
#include <iostream>
#include <string>
#include <cmath>
//using namespace std;
bool isLeapYear(int);
int getCenturyValue(int);
int getYearValue(int);
void getInput(int, int ,int);
void returnWeekDay(int, std::string);
int main() {
int year = 0;
int month = 0;
int day = 0;
/*int month = int();
int day = int();*/
int dayOfWeek = int();
//int century = int();
//int yearValue = int();
std::string weekDay;
int dayOfWeekRem = int();
getInput(year, month, day);
bool leapYear = isLeapYear(year);
int century = getCenturyValue(year);
int yearValue = getYearValue(year);
dayOfWeek = day + ((13 * (month + 1)) / 5) + (yearValue)
+ (yearValue / 4) + (century / 4) - (2 * century);
returnWeekDay(dayOfWeek, weekDay);
system("pause");
}
void getInput(int year, int month, int day) {
std::cout << "Enter a year: ";
std::cin >> year;
std::cout << "Enter a month (1-12): \n";
std::cout << "Jan. = 1\n";
std::cout << "Feb. = 4\n";
std::cout << "Mar. = 3\n";
std::cout << "Apr. = 6\n";
std::cout << "May. = 1\n";
std::cout << "Jun. = 4\n";
std::cout << "Jul. = 6\n";
std::cout << "Aug. = 2\n";
std::cout << "Sep. = 5\n";
std::cout << "Oct. = 0\n";
std::cout << "Nov. = 3\n";
std::cout << "Dec. = 5\n";
std::cin >> month;
std::cout << "Enter a day (1-31): ";
std::cin >> day;
}
bool isLeapYear(int year) {
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0) {
std::cout << "This year is a leap year.\n";
return true;
}
else {
std::cout << "This year is not a leap year.\n";
return false;
}
}
else {
std::cout << "This year is not a leap year.\n";
return true;
}
}
/*else {
std::cout << "This year is not a leap year.\n";
return false;
}*/
return false;
}
int getCenturyValue(int year) {
return year / 100;
}
int getYearValue(int year) {
return year % 100;
}
void returnWeekDay(int dayOfWeek, std::string weekDay) {
/*std::string weekDay;
int dayOfWeek = int();*/
if (dayOfWeek == 0) {
std::cout << "This is a Sunday.";
}
if (dayOfWeek == 1) {
std::cout << "This is a Monday.";
}
if (dayOfWeek == 2) {
std::cout << "This is a Tuesday.";
}
if (dayOfWeek == 3) {
std::cout << "This is a Wednesday.";
}
if (dayOfWeek == 4) {
std::cout << "This is a Thursday.";
}
if (dayOfWeek == 5) {
std::cout << "This is a Friday.";
}
if (dayOfWeek == 6) {
std::cout << "This is a Saturday.";
}
if (dayOfWeek > 7) {
std::cout << "I STILL NEED TO DO THIS IF STATEMENT";
}
}
|