Is Friday the 13th really an unusual event?
That is, does the 13th of the month land on a Friday less often than on any other >day of the week? To answer this question, write a program that will compute the frequency that the 13th of each month lands on Sunday, Monday, Tuesday, >Wednesday, Thursday, Friday, and Saturday over a given period of N years. The >time period to test will be from January 1, 1900 to December 31, 1900+N-1 for a >given number of years, N. N is positive and will not exceed 400.
Here's what I have:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main(){
ifstream fin("fridayin.txt");
ofstream fout("fridayout.txt");
int N;
fin >> N;
int current_year, end_year = 1900 + N - 1, current_day = 1; //set current_year, end_year, and current_day to 1(Monday)
int daycounter[7] = { 0 }; //this will record how many times a day occurs on the 13th
int current_month = 1;
int day;
for (current_month = 1; current_month <= 12; current_month++){
for (current_year = 1900; current_year <= end_year; current_year++){ //jan 13=saturday
int yp = current_year - 1900;
if (current_year < 2000){ //2000 is a leap year
day = (6 + yp + yp / 4 - yp / 100) % 7;
daycounter[day]++; //increment the day counter
}
else if (current_year > 2000){ //check if it's after 2000, if it is add 1 to 6 to get 0 (mod 7)
day = (yp + yp / 4 - yp / 100) % 7;
daycounter[day]++; //increment the day counter
}
}
}
int i;
for (i = 0; i < 7; i++){
fout << daycounter[i] << ' ';
}
return 0;
}
I'm computing the January 13ths then the February 13ths,... December 13ths.
Here's input:
20
Correct output:
36 33 34 33 35 35 34
My output:
48 36 36 24 24 36 36
I think I know what's wrong, since January 13th, 1900 is a Saturday I made it 6 mod 7 but that's not true for February 13th, 1900 and the other months. I'd have to change the equations and create an if statement but that'd be extremely long.