When I complie and run my program it works but no matter what day you say January first is it sets it as monday. Any ideas on how to fix this?
#include <iostream>
#include <fstream>
#include <iomanip>
#include <fstream>
using namespace std;
int year, month, FDOM, mDays;
int getYear();
int getFirstDay();
void weeks(int w, int days);
int printCalMonth(int FDOM, int month, int);
void space(int start, int& columnt, int month, int& prev);
void numbers(int month, int& days, int& spaceDays);
int i = 0;
int days;
int spaceDays;
int first;
int prev;
int column;
int w = 1;
bool leapYear( int year);
int main()
{
year = getYear();
FDOM = getFirstDay();
cout << endl << endl;
cout << " " << year << endl;
cout << endl << endl;
for(month = 0; month < 12; month++)
{
FDOM = printCalMonth( FDOM, month, mDays);
}
return 0;
}
int getYear()
{
int year;
cout << " Please enter year" << endl;
cin >> year;
return year;
}
int getFirstDay()
{
int FDOM;
cout << "What day is January first start on" << endl;
cin >> FDOM;
return FDOM;
}
int printCalMonth(int FDOM, int month, int days)
{
if (month == 1)
{
cout << " January \n" << endl;
cout << " S M T W T F S \n\n";
}
if (month == 2)
{
cout << " February \n";
cout << " S M T W T F S \n\n";
}
if (month == 3)
{
cout << " March \n";
cout << " S M T W T F S \n\n";
}
if (month == 4)
{
cout << " April \n";
cout << " S M T W T F S \n\n";
}
if (month == 5)
{
cout << " May \n";
cout << " S M T W T F S \n\n";
}
if (month == 6)
{
cout << " June \n";
cout << " S M T W T F S \n\n";
}
if (month == 7)
{
cout << " July \n";
cout << " S M T W T F S \n\n";
}
if (month == 8)
{
cout << " August \n";
cout << " S M T W T F S \n\n";
}
if (month == 9)
{
cout << " September \n";
cout << " S M T W T F S \n\n";
}
if (month == 10)
{
cout << " October \n";
cout << " S M T W T F S \n\n";
}
if (month == 11)
{
cout << " November \n";
cout << " S M T W T F S \n\n";
}
if (month == 12)
{
cout << " December \n";
cout << " S M T W T F S \n\n";
}
numbers( month, days, spaceDays);
space( first, column, month, prev);
weeks( w, days);
return FDOM;
}
bool leapYear(int year)//Function to calculate whether year is a leap year
{
if (year % 4 ==0)
return true;
else
return false;
}
void weeks(int w, int days)
{
while (w <= days)
{
if (column == 7)
{
cout << endl;
column = 0;
}
cout << setw(3);
cout << w;
column++;
w++;
}
column = 0;
cout << endl << endl;
}
void numbers(int month, int& days, int& spaceDays) // previous and current days in each month
{
switch (month)
{
case 1:
days = 31; // Number of days in january
break;
case 2:
if(leapYear(year)) // If there is a leap year in Febuary
days = 29;
if(!leapYear(year))
days = 28;
spaceDays = 31; // Number of days in the month before
break;
case 3:
days = 31;
if(leapYear(year))
spaceDays = 29;
if(!leapYear(year))
spaceDays = 28;
break;
case 4:
days = 30;
spaceDays = 31;
break;
case 5:
days = 31;
spaceDays = 30;
break;
case 6:
days = 30;
spaceDays = 31;
break;
case 7:
days = 31;
spaceDays = 30;
break;
case 8:
days = 31;
spaceDays = 31;
break;
case 9:
days = 30;
spaceDays = 31;
break;
case 10:
days = 31;
spaceDays = 30;
break;
case 11:
days = 30;
spaceDays = 31;
break;
case 12:
days = 31;
spaceDays = 30;
break;
}
}
void space(int first, int& column, int month, int& prev) // print spaces
{
if (month == 1)
{
int loopCount;
for (loopCount = 0; loopCount < first; loopCount++)
{
cout << " ";
prev++;
}
column =+ first; // First is equal to Start + column
}
else if (month != 1)
{
int otherSpacer;
int loopCount;
int monthCount = month;
numbers(monthCount, days, spaceDays);
otherSpacer = (prev + spaceDays) % 7;
prev = 0;
for (loopCount = 0; loopCount < otherSpacer; loopCount++)
{
cout << " ";
prev++;
column =+ otherSpacer;
}
}
}