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
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int mdays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int DaysinWeek = 0;
int year;
int day;
int FirstDayOfMonth = 0;
int month = 1;
cout << "Calendar Program" << endl << endl;
cout << "Please enter the year: ";
cin >> year;
if (year < 0)
{cout << "The year must be greater than or equal to 0!" << endl;
return 0;}
cout << "Please enter the day of the week of January 1st." << endl;
cout << "Enter 0 for Sunday, 1 for Monday, ..., 6 for Saturday: ";
cin >> day;
if (day < 0 || day > 6)
{cout << "The day of January 1st must be between 0 and 6!" << endl;
return 0;}
cout << endl << endl;
// Print this year's calendar
for (int month = 0; month < 12; ++month) {
{
for (int i = 0; i < DaysinWeek; ++i)
{cout << setw(3) << " ";}
if (month == 0)
{cout << "January \n";}
if (month == 1)
{cout << "February \n";
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
mdays[1] = 29;}
if (month == 2)
{cout << "March \n";}
if (month == 3)
{cout << "April \n";}
if (month == 4)
{cout << "May \n";}
if (month ==5)
{cout << "June \n";}
if (month == 6)
{cout << "July \n";}
if (month == 7)
{cout << "August \n";}
if (month == 8)
{cout << "September \n";}
if (month == 9)
{cout << "October \n";}
if (month == 10)
{cout << "November \n";}
if (month == 11)
{cout << "December \n";}
}
//spaces
for (int i = 0; i < day; i++)
{cout << " ";
}
//Determine where the first day begins
day = 0;
for (FirstDayOfMonth; FirstDayOfMonth < day; ++FirstDayOfMonth)
{
cout << setw(3);
}
// Print this month's calendar
for (int mday = 0; mday < mdays[month]; ++mday) {
cout << setw(3) << mday + 1;
DaysinWeek++;
if (DaysinWeek == 7) {
cout << "\n" << setw(3);
DaysinWeek = 0;
}
}
// Set up for the next month
if (DaysinWeek != 7) {
cout << "\n";
}
cout << endl;
day = DaysinWeek + 1;
}
system("pause");
return 0;
}
|