Question: namespace Assignment { enum Month { January = 1, February, March, April, May, June, July, August, September, October, November, December } class Calendar { static

namespace Assignment { enum Month { January = 1, February, March, April, May, June, July, August, September, October, November, December }

class Calendar { static void Main(string[] args) { int year; int firstDay;

do { Console.Write("Enter the year for which you wish to generate the calendar: ");

while (!int.TryParse(Console.ReadLine(), out year)) { Console.Write("Invalid input. Please enter a valid year: "); }

Console.Write("Enter the day of the week that January first is on: "); while (!int.TryParse(Console.ReadLine(), out firstDay) || firstDay < 0 || firstDay > 6) { Console.Write("Invalid input. Please enter a valid day of the week: "); }

Console.WriteLine(" "); Console.WriteLine("Calendar for the year " + year);

for (int month = (int)Month.January; month <= (int)Month.December; month++) { Console.WriteLine(); Console.WriteLine(Enum.GetName(typeof(Month), month)); Console.WriteLine("Sun\tMon\tTue\tWed\tThu\tFri\tSat");

int daysInMonth; if (month == 2) { if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) { daysInMonth = 29; } else { daysInMonth = 28; } } else if (month == 4 || month == 6 || month == 9 || month == 11) { daysInMonth = 30; } else { daysInMonth = 31; }

for (int i = 0; i < firstDay; i++) { Console.Write("\t"); }

for (int day = 1; day <= daysInMonth; day++) { Console.Write(day + "\t");

if ((firstDay + day) % 7 == 0) { Console.WriteLine(); } }

firstDay = (firstDay + daysInMonth) % 7; } Console.Write(" Do you want to generate a calendar for another year? (y/n): ");//another year prompt } while (Console.ReadLine().ToLower() == "y"); } } }

How do I rewrite this using Switch Statements?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!