Enter a Year Print out a calendar

we are given an algorithm
a=(14-month)/12;
y=year-a;
m= month+12*a-2;
startday=(day+y+y/4-y/100 + y/400 + (31*m/12))%7;

I think I understand the concept but i cannot make this work
this is what i have so far
We are also suppose to put the program in another file but I commented all that out until i actually have the program down.


#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;


void calendar(const int month, const int startday, const bool leap);
int daysofmonth [13]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
const string STRMONTHS[13] = {" ", "Janurary", "February","March","April","May","June","July","August","September","October","November","December"};

int inputyear(void)
{
int year;
cout << "Enter a 4 digit year greater than 1582: ";//finds year user wants
cin >> year;
while (year < 1582 || year > 9999)
{
cout << "Invalid, Please enter a year greater than 1582 and less than 9999: ";
cin >> year;
}
return year;
}

bool isLeapYear(int year)
{
bool leap = false;
if (year % 100 == 0) {
if (year % 400 == 0) {
leap = true;
}
} else if (year % 4 == 0) {
leap = true;
}
return leap;
}

void printmonthname (const int M, ostream & mf)//Spaces the month names out
{
int width = 14+(STRMONTHS[M].length()/2);
mf<<setw(width) << STRMONTHS[M] << endl;

}
//int main(void)
//{
//ofstream myfile;
//myfile.open("cal.dat");
//for (int month=1; month<=12; month++)
//{
//printmonthname (month.myfile);
//}

//return 0;
//}
//void inputyear (const int Y, ostream & mf)
//{
//int year;
//ofstream myfile;
//myfile.open("cal.dat");
//{
//inputyear (year.myfile);
//}
//}

int determinedaycode (int year)
{
int daycode;
int a, month, y, m, day, startday;
a=(14-month)/12;
y=year-a;
m= month+12*a-2;
startday=(day+y+y/4-y/100 + y/400 + (31*m/12))%7;

return daycode;
}


void calendar (int year, int daycode)
{
int month, startday;
cout << endl << setw(14 + (STRMONTHS[month].size ()/2)) << STRMONTHS[month] << endl;
cout << " Sun Mon Tue Wed Thu Fri Sat" << endl;
for (int index=1; index<=startday; index++)
cout << setw(4) << ' ';

for (int index=1; index<= daysofmonth[month]; index++)
{
cout << setw(4) <<index;
if ((index + startday) %7 == 0) cout <<endl;
}

}

int main(void)
{
int year, daycode, leapyear;

year = inputyear();
daycode = determinedaycode(year);
calendar(year, daycode);
cout << "\n" << endl;
}
Topic archived. No new replies allowed.