Answer to Question #343894 in C# for mee

Question #343894

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-23T15:17:54-0400
using System;
namespace ConsoleApp1
{
  class Program
  {
    public enum Month
    {
      January = 1,
      February,
      March,
      April,
      May,
      June,
      July,
      August,
      September,
      October,
      November,
      December
    }
    static void Main(string[] args)
    {
      string str = "";
      int Number;
      while (str != "Exit" && str != "E" && str != "exit" && str != "e")
      {
        Console.Write("Write a number from 1 to 12 (Or write the Exit): ");
        str = Console.ReadLine();
        if (int.TryParse(str, out Number))
          if (Number >= 1 && Number <= 12)           
            Console.WriteLine((Month)Number);
      }
    }
  }
}

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