repl.it
@cream_puff_four/

Day calculator

C++

No description

fork
loading
Files
  • main.cpp
main.cpp
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
#include <iostream>
#include <cmath>
using namespace std;

void copy(int a[], int b[], int length ){
	for(int i=0;i<length;i++){
		  a[i] = b[i];
	}
}

int main() {
	cout<<"Enter year number between 2000 & 2099"<< endl;
	int year;
	cin>>year;
	while (year > 2099 || year < 2000) {
		cout<<"Enter a year between 2000 and 2099"<< endl;
		cin>>year;
	}
	int yearCode = ((int)(floor(year / 4) + year)) % 7;
	cout<<"Enter month number."<< endl;
	int month;
	cin>>month;
	int code [12]={};

	int codeLeapYear[12] =  {5, 1, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
  int codeNormalYear[12] = {6, 2, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};

	if (year % 4 ==0) {
		copy(code, codeLeapYear,12);
	}
	else {copy(code, codeNormalYear, 12); 
	}

	int monthCode = code [month - 1];
	
	cout<<"Enter day number"<< endl;
	int day;
	cin>>day;
	string week[7] = {"Monday", "Tuesday", "Wednesday","Thursday", "Friday","Saturday", "Sunday"};
	cout<<week[(monthCode + day + yearCode - 2) % 7]<< endl;

	string answer;
	cout<<"Did I get it right?"<< endl;
	cin>>answer;
	if (answer == "yes") {
		cout<<" __________________________"<< endl;
		cout<<"|                          |"<< endl;
		cout<<"|      |           |       |"<< endl;
		cout<<"|          |   |           |"<< endl;
		cout<<"|        |______|          |"<< endl;
		cout<<"|                          |"<< endl;
		cout<<"|    |_________________|   |"<< endl;
		cout<<"|__________________________|"<< endl;
	} else {
		 cout<<"Boo hoo hoo";
	}
}