It is known that November 1993 starts on a Monday. Make a program that would input a numeric day(between 1 and 30) and output the day of the week the day falls. For example, if 3 is entered for day, the program must display "WEDNESDAY", if 8 was entered,"MONDAY" must be displayed and so on...
1
Expert's answer
2012-07-19T07:29:12-0400
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int NumericDay;
ConsoleKeyInfo KeyInfo; do{
do{ Console.WriteLine ("Input a numeric day(between 1 and 30):"); while(! int.TryParse (Console.ReadLine(), out NumericDay)) { Console.WriteLine ("Input a numeric day(between 1 and 30):");
} if ((NumericDay < 1) || (NumericDay > 30)) { Console.WriteLine ("ERROR! A numeric day must be between 1 and 30!"); }
else break;
} while(true);
NumericDay = NumericDay % 7;
switch (NumericDay) { case 0:
Console.WriteLine("SUNDAY");
break; case 1:
Console.WriteLine("MONDAY");
break; case 2:
Console.WriteLine("TUESDAY");
break; case 3:
Console.WriteLine("WEDNESDAY");
break; case 4:
Console.WriteLine("THURSDAY");
break; case 5:
Console.WriteLine("FRIDAY");
break; case 6:
Console.WriteLine("SATURDAY");
break; default: break;
} Console.WriteLine ("Press any key to continue OR Escape to Quit"); KeyInfo = Console.ReadKey (); } while(KeyInfo.Key != ConsoleKey.Escape); } } }
Comments
Leave a comment