Answer to Question #343639 in C# for kun

Question #343639

Create an enumeration named Month that holds values for the months of the year, starting with January equal to 1. Write a program that prompts the user for a month integer. Convert the user’s entry to a Month value, and display it.


1
Expert's answer
2022-05-22T18:12:05-0400
using System;

namespace Program
{
    enum Month
    {
        January = 1,
        February = 2,
        March = 3,
        April = 4,
        May = 5,
        June = 6,
        July = 7,
        August = 8,
        September = 9,
        October = 10,
        November = 11,
        December = 12
    }

    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter month number: ");
            string input = Console.ReadLine();
            int month_num = Int32.Parse(input);
            Month month = (Month)month_num;
            Console.WriteLine(month.ToString());
        }
    }
}

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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS