using System; namespace calendar { class Program { static int day_1; static int month_1; static int year_1; static int day_2; static int month_2; static int year_2; static int increase_amount; static int TakeMonthName(string month) { switch (month.ToLower()) { case "january": return 1; case "february": return 2; case "march": return 3; case "april": return 4; case "may": return 5; case "june": return 6; case "july": return 7; case "august": return 8; case "september": return 9; case "october": return 10; case "november": return 11; case "december": return 12; default: return 0; } } static string TakeMonthInt(int month) { //for translating month name to integer switch (month) { case 1: return "january"; case 2: return "february"; case 3: return "march"; case 4: return "april"; case 5: return "may"; case 6: return "june"; case 7: return "july"; case 8: return "august"; case 9: return "september"; case 10: return "october"; case 11: return "november"; case 12: return "december"; default: return "undefined"; } } static string GetMonthsSeasons(int month) { switch (month) { case 12: case 1: case 2: return "winter"; case 3: case 4: case 5: return "spring"; case 6: case 7: case 8: return "summer"; case 9: case 10: case 11: return "autumn"; default: return "undefined"; } } static int GetNullDay(int month) { switch (month) { case 1: return 1; case 2: return 12; case 3: return 5; case 4: return 2; case 5: return 7; case 6: return 4; case 7: return 9; case 8: return 6; case 9: return 3; case 10: return 8; case 11: return 12; case 12: return 10; default: return 1200; } } static string GetDayNames(int day, int month, int year) { int NullDay = GetNullDay(month); string yearString = Convert.ToString(year); // this is for the numbers of formula string centuryS = yearString.Substring(0, 2); int century = Convert.ToInt32(centuryS); int yearC_control = year - century * 100; int yearC_4 = yearC_control % 10; int yearC_3 = (yearC_control - yearC_4) / 10; double W_0 = (yearC_4 / 4) - (yearC_3 / 2); double W_1 = Math.Round(W_0); if (W_0 < W_1) { W_1 += W_1 - 1; W_1--; } double WoDN_1 = day - NullDay + yearC_4 - yearC_3 + W_1 - (2 * (century % 4)); double weekofday_number; while (WoDN_1 < 0) { WoDN_1 += WoDN_1 + WoDN_1; WoDN_1++; } weekofday_number = WoDN_1 % 7; switch (weekofday_number) { case 1: return "monday"; case 2: return "tuesday"; case 3: return "wednesday"; case 4: return "thursday"; case 5: return "friday"; case 6: return "saturday"; case 0: return "sunday"; default: return "undefined"; } } static bool isLeapYear(int year) { if (year % 4 == 0 && year % 100 != 0) return true; else if (year % 400 == 0 && year % 4000 != 0) return true; else return false; } static int exceptDayLength(int month, int year) { if (month == 2) return isLeapYear(year) ? 29 : 28; int monthd = month % 2; if (month <= 7) return monthd == 1 ? 31 : 30; return monthd == 1 ? 30 : 31; } static void getDate1() { int day = 0; string month = "month"; int year = 0; bool isValid = false; Console.WriteLine("Getting date 1"); while (!isValid) { try { Console.WriteLine("Please enter the day as a number."); day = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Please enter the month as string. "); month = Console.ReadLine(); Console.WriteLine("Please enter the year."); year = Convert.ToInt32(Console.ReadLine()); isValid = validate(day, month, year); } catch { isValid = false; } if (!isValid) { Console.WriteLine("please enter a valid date"); Console.WriteLine("Getting date 1"); } } day_1 = day; month_1 = TakeMonthName(month); year_1 = year; } static void getDate2() { int day = 0; string month = "month"; int year = 0; bool isValid = false; Console.WriteLine("Getting date 2"); while (!isValid) { try { Console.WriteLine("Please enter the day as a number."); day = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Please enter the month as string. "); month = Console.ReadLine(); Console.WriteLine("Please enter the year."); year = Convert.ToInt32(Console.ReadLine()); isValid = validate(day, month, year); } catch { isValid = false; } if (!isValid) { Console.WriteLine("please enter a valid date"); Console.WriteLine("Getting date 2"); } } day_2 = day; month_2 = TakeMonthName(month); year_2 = year; } static bool validate(int day, string month, int year) { int monthIndex = TakeMonthName(month); if (year > 10000 || year < 2015) return false; if (monthIndex == 0) return false; if (day > exceptDayLength(monthIndex, year)) return false; if (day <= 0) return false; return true; } static void checkDates() { static bool valid() { if (year_2 < year_1) return false; if (month_2 < month_1 && year_2 == year_1) return false; if (day_2 < day_1 && month_1 == month_2 && year_1 == year_2) return false; return true; } bool isValid = valid(); if (!isValid) { Console.WriteLine("the second date mus be later than first date"); getDate2(); checkDates(); } } static void printCalendar() { int extraDay = 0; string currentSeason = ""; for (int year = year_1; year <= year_2; year++) { int exceptMonth = year == year_2 ? month_2 : 12; int startMonth = year == year_1 ? month_1 : 1; for (int month = startMonth; month <= exceptMonth; month++) { if (currentSeason != GetMonthsSeasons(month)) { currentSeason = GetMonthsSeasons(month); Console.WriteLine(currentSeason); } int exceptDay = year == year_2 && month == month_2 ? day_2 : exceptDayLength(month, year); int startDay = year == year_1 && month == month_1 ? day_1 : 1; startDay += extraDay; for (int day = startDay; day <= exceptDay;) { Console.WriteLine(day + " " + TakeMonthInt(month) + " " + year + " " + GetDayNames(day, month, year)); day += increase_amount; if (day > exceptDay) { extraDay = day - exceptDay - 1; } if (day == exceptDay) { extraDay = 0; } } } } } static void Main(string[] args) { getDate1(); getDate2(); checkDates(); Console.WriteLine("Please enter the increase amount of the days."); increase_amount = Convert.ToInt32(Console.ReadLine()); printCalendar(); //for null days } } }