Help printing Calendar to file

I have finished everything with my code except for printing the year ond the months to a file.
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
const int MIN = 1582;
const int MAX = 9999;
int startday[7] = { 0, 1, 2, 3, 4, 5, 6 };
int daysinmonths[13] = { 0, 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 };
const string MONTHS[13] = { " ", "January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November", "December" };
bool isleapyear(const int year);
void printyear(ofstream & f, const int year);
int dayofweek(int month, int year);
int main(void){
int year1;
ofstream myfile;
myfile.open("calendar.txt");
cout << "Please enter a year between 1582 and 9999\nto obtain the full calendar year of that date.\n";
cin >> year1;
while (year1 < MIN || year1 > MAX){
cout << "Incorrect input, please enter a year within the range of 1582 through 9999!\n";
cin >> year1;
}

printyear(myfile, year1);



return 0;
}


bool isleapyear(const int year){

if ((year % 400 == 0) == true &&! (year % 100 == 0)){
daysinmonths[2] = 28;
cout << "This is a leap year.\n" << endl;
}
else if ((year % 4 == 0) == true){
daysinmonths[2] = 28;
cout << "This is a leap year.\n" << endl;
}

return year;
}

int dayofweek(const int month, const int year){
int a, y, m, d;

a = (14 - month) / 12;
y = year - a;
m = month + 12 * a - 2;
d = (1 + y + y / 4 - y / 100 + y / 400 + (31 * m / 12)) % 7;
for (int x = 0; x < d; x++){
cout << " ";
}
for (int count = 0; count <= daysinmonths[month]; count++){
if ((count + d) % 7 == 0){
cout << endl << " ";
}
if (count + 1 < 10)
cout << " ";
cout << count + 1 << " ";
}


return year;
}
void printyear(ofstream & f, const int year){

isleapyear(year);






int length = 0;
cout << setw(17) << year;
for (int count = 1; count <= daysinmonths[count]; count++)
{


length = MONTHS[count].length();
length = (30 - length) / 2 + length;

cout << setw(length);
cout << endl << endl << endl << setw(length) << MONTHS[count] << endl;

cout << " Sun Mon Tue Wed Thu Fri Sat\n";
cout << " ";
dayofweek(count, year);
}
cout << endl << endl;
}

I noticed if your starting day for the month is not Sunday, the numbers in the first week don't line up the way you would expect.

If you change the days of week to 2 char it will also line up better with the 2 char day of week.
cout << " Su Mo Tu We Th Fr Sa\n";

To write to a file you just turn the << around to look like >>.
myfile >> " Su Mo Tu We Th Fr Sa\n";
Topic archived. No new replies allowed.