68 245
Assignments Done
Successfully Done
In November 2018

Answer to Question #62278 in C# for Peter

Question #62278
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
Expert's answer
using System;
using System.Globalization;

namespace DateApp
class Program
static int CheckInput(string str, int lowerLim, int upperLim)
int dateVal;
string date;
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");

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions