Skip to content

Instantly share code, notes, and snippets.

@GlowingAshes
Created January 30, 2017 09:50
Show Gist options
  • Save GlowingAshes/6540b57a847906a579d2b86e9c3215f4 to your computer and use it in GitHub Desktop.
Save GlowingAshes/6540b57a847906a579d2b86e9c3215f4 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
int userDay = 0;
int userYear = 0;
int userMonth = 0;
int month = 0;
int year = 0;
int h = 0;
int q = 0;
int m = 0;
int k = 0;
int j = 0;
string day = " ";
cin >> month;
cin >> year;
userMonth = month;
userYear = year;
userDay = 1;
if (userMonth == 1) {
userMonth = 13;
userYear -= 1;
}
if (userMonth == 2) {
userMonth = 14;
userYear -= 1;
}
q = userDay;
m = userMonth;
k = userYear % 100;
j = userYear/100;
h = (q + ((13*(m+1))/5)+k+(k/4)+(j/4)+(5*j)) % 7;
// 0 = saturday, 1 = sunday, 2 = monday, 3 = tuesday, 4 = wednesday, 5 = thursday, 6 = friday
switch (month) {
case 1:
day = "January";
break;
case 2:
day = "February";
break;
case 3:
day = "March";
break;
case 4:
day = "April";
break;
case 5:
day = "May";
break;
case 6:
day = "June";
break;
case 7:
day = "July";
break;
case 8:
day = "August";
break;
case 9:
day = "September";
break;
case 10:
day = "October";
break;
case 11:
day = "November";
break;
case 12:
day = "December";
break;
}
cout << setw((15 - day.length()) /2 ) << " " << day << " " << year << endl; // professor agorithm of literally crap and badness.
cout << "Su" << " " << "Mo" << " " << "Tu" << " " << "We" << " " << "Th" << " " << "Fr" << " " << "Sa" << endl;
int i = 0;
int n = 0;
int p = 0;
int o = 0;
switch (h) {
case 0: // saturday
n = 7;
cout << setw(18) << " "; // 18 spaces
break;
case 1: // sunday
n = 1;
break;
case 2: // monday
n = 2;
cout << setw(3) << " "; // 3 spaces
break;
case 3: // tuesday
n = 3;
cout << setw(6) << " "; // 6 spaces
break;
case 4: // wednesday
n = 4;
cout << setw(9) << " "; // 9 spaces
break;
case 5: // thursday
n = 5;
cout << setw(12) << " "; // 12 spaces
break;
case 6: // friday
n = 6;
cout << setw(15) << " "; //15 spaces
break;
}
p = 1;
switch (month) {
case 9:
case 4:
case 6:
case 11:
o = 30;
break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
o = 31;
break;
case 2:
if ((year % 4 == 0 && year % 100 != 0) || ( year % 400 == 0)) {
o = 29;
}
else {
o = 28;
}
}
while(true) {
for (i = n; i < 8; i++) {
if((i==7) || (p == o)) {
cout << setw(2) << p << endl;
}
else {
cout << setw(2) << p << " ";
}
p ++;
if (p > o) {
break;
}
}
n = 1;
if (p > o) {
break;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment