Create an app that asks the user to enter a number that represents a month of the year and also asks them to enter a year. When entered, the app should then display the month and say if their chosen year is a leap year or not.
Example: If the user inputs the number 2, it should then Display February
1
Expert's answer
2016-09-29T14:29:04-0400
using System; using System.Globalization;
namespace DateApp { class Program { static int CheckInput(string str, int lowerLim, int upperLim) { int dateVal; string date; do { Console.WriteLine(str); date = Console.ReadLine(); } while (!int.TryParse(date, out dateVal) || Convert.ToInt32(date) < lowerLim || Convert.ToInt32(date) > upperLim); return dateVal; } static void Main(string[] args) { string monthMessage = "Type a month number [1-12]:", yearMessage = "Type year [1000-9999]:"; int month = CheckInput(monthMessage, 1, 12), year = CheckInput(yearMessage, 1000, 9999); string monthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(month); Console.WriteLine("\nRESULTS:\nMonth: {0}", monthName); Console.WriteLine("Year {0} is {1} leap", year, DateTime.IsLeapYear(year) ? "" : "not"); } } }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment