help with a date program

I need to count the number of days that that date 13 appears in every month and on what day it happens from jan 1, 1900 to dec 31, 1900+N-1. N is a number that is received from a txt file (Don't need to do that part right now). I am using 20 for N and the output starts with saturday and the answer should be
36 33 34 33 35 35 34. My code has answers that seem to be off by 1 for some of them.
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
//counts the number of days the date 13 appears from jan 1, 1900 to dec 31, 1900+N-1, N is the only input
//jan 1, 1900 was a monday
#include <iostream>
#include <fstream>
#include <string>

using namespace std;
//{1=31, 2=28, 3=31, 4=30, 5=31, 6=30, 7=31, 8=31, 9=30, 10=31, 11=30, 12=31}
int main()
{
	ifstream in("friday.txt");
	ofstream out("friday.out");

	/*int saturday =0;
	int sunday =0;
	int monday =0;
	int tuesday =0;
	int wednesday =0;
	int thursday =0;
	int friday =0;*/
	//used for counting the number of times each day in on the 13th 
	int dayname[7] ={0, 0, 0, 0, 0, 0, 0};

	string day[7] = {"saturday", "sunday", "monday", "tuesday", "wednesday", "thursday", "friday"};


	//starts on monday
	int current =2;
	//string current_day = day[current];


	int N;
	//in >> N;
	N=20;

	int days;

	for(int y=1900;y<=(1900+N-1); y++)
	{
		for(int m=1; m <= 12; m++)
		{
			switch(m)
			{
			case 1: days =31;
			case 2: 
				if(y%4 ==0 && y%100 != 0)
					days =29;
				else if(y%100 ==0 && y%400 ==0)
					days =29;
				else
					days=28;
			case 3: days =31;
			case 4: days =30;
			case 5: days =31;
			case 6: days =30;
			case 7: days =31;
			case 8: days =31;
			case 9: days =30;
			case 10: days =31;
			case 11: days =30;
			case 12: days =31;
			}

			for(int d=1; d<=days; d++)
			{
				//current_day = day[current];

				if(d ==13)
				{
					dayname[current]++;
				}

				if(current ==6)
					current =0;
				else
					current++;
			}//day loop

		}//month loop

	} //year loop

	for(int t=0; t<7; t++)
	{
		cout << dayname[t] << endl;
	}

	in.close();
	out.close();

	return(0);
}
It's from the USACO training right? LOL, you ask help for it here. Anyways, this is the pseudocode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
input n;
int days[12]:={31,28,31,30,31,30,31,31,30,31,30,31}, count13[7];
fillWithZeros(count13);
k:=12
for i:=0 to n-1 do
{
     for j:=0 to 11 do
     {
           increment count13[k%7];
           k:=k+days[j];
           if j=1 and (1900+i mod 4)=0 and ((1900+i mod 100)!=0 or (1900+i mod 400)=0) then increment k;
           }
     }
output count13;
Last edited on
why do you do k%7 in increment count13?
because, k is the number of days you've gone throug, and a week only has 7 days. k%7 is the number of the day in the week the program's at.
Topic archived. No new replies allowed.