title: How to use C# Enums in Switch Statement while keeping the rest of the code the same
body: <p>I am making a C# maths project where the user answers an addition, subtraction, multiplication, division, power or square root question based on the difficulty level they choose!</p>
  
  <p>I have just started using Enums but I don't know how to put it in my switch statements so the rest of my code works fine.</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>using System;
  
  namespace mathstester
  {
      class Program
      {
          public enum UserDifficulty
          {
              Easy,
              Normal,
              Hard
          }
  
          public enum MathOperation
          {
              Addition = 1,
              Subtraction = 2,
              Multiplication = 3,
              Division = 4,
              Power = 5,
              SquareRoot = 6
          }
          public static (int operationMin, int operationMax) GetMathOperationForDifferentDifficulties(UserDifficulty userDifficulty)
          {
  
              switch (userDifficulty)
              {
                  case UserDifficulty.Easy:
                      return (1, 4);
                  case UserDifficulty.Normal:
                      return (1, 5);
                  case UserDifficulty.Hard:
                      return (3, 7);
                  default:
                      throw new Exception();
              }
          }
  
          public static (string message, double correctAnswer) GetMathsEquation(MathOperation mathOperation, UserDifficulty userDifficulty)
          {
              int number1;
              int number2;
              Random random = new Random();
  
              switch (mathOperation)
              {
                  case MathOperation.Addition:
                      number1 = random.Next(1000);
                      number2 = random.Next(1000);
                      return ($"{number1} + {number2}", number1 + number2);
                  case MathOperation.Subtraction:
                      number1 = random.Next(1000);
                      number2 = random.Next(1000);
                      return ($"{number1} - {number2}", number1 - number2);
                  case MathOperation.Multiplication:
                      number1 = userDifficulty == UserDifficulty.Easy ? random.Next(13) : random.Next(1000);
                      number2 = userDifficulty == UserDifficulty.Easy ? random.Next(13) : random.Next(1000);
                      return ($"{number1} * {number2}", number1 * number2);
                  case MathOperation.Division:
                      number1 = random.Next(10000);
                      number2 = random.Next(1000);
                      return ($"{number1} / {number2}", number1 / (double)number2);
                  case MathOperation.Power:
                      number1 = random.Next(13);
                      number2 = random.Next(5);
                      return ($"{number1} ^ {number2}", Math.Pow(number1, number2));
                  case MathOperation.SquareRoot:
                      number1 = random.Next(1000);
                      return ($"√{number1}", Math.Sqrt(number1));
                  default:
                      throw new Exception();
              }
          }
  
          public static int GetResult(int numberOfQuestionsLeft, string userDifficulty)
          {
              int score = 0;
              Random random = new Random();
              var (operationMin, operationMax) = GetMathOperationForDifferentDifficulties(userDifficulty);
              while (numberOfQuestionsLeft &gt; 0)
              {
                  int mathOperation = random.Next(operationMin, operationMax);
                  var (message, correctAnswer) = GetMathsEquation(mathOperation, userDifficulty);
                  if (mathOperation == 4 || mathOperation == 6)
                  {
                      Console.Write($"To the nearest integer, What is {message} =");
                  }
                  else
                  {
                      Console.Write($"What is {message} =");
                  }
                  double userAnswer = Convert.ToDouble(Console.ReadLine());
                  if (Math.Round(correctAnswer) == userAnswer)
                  {
                      Console.WriteLine("Well Done!");
                      score++;
                  }
                  else
                  {
                      Console.WriteLine("Your answer is incorrect!");
                  }
                  numberOfQuestionsLeft--;
              }
  
              return score;
          }
  
          public static void Main(string[] args)
          {
              string userDifficulty = "";
              do
              {
                  Console.WriteLine("What difficulty level would you like to do! Please type E for Easy, N for Normal and H for hard");
                  userDifficulty = Console.ReadLine().ToUpper();
              } while (userDifficulty != "E" &amp;&amp; userDifficulty != "N" &amp;&amp; userDifficulty != "H");
  
              int numberOfQuestions = 0;
              do
              {
                  Console.WriteLine("How many questions would you like to answer? Please type a number divisible by 10!");
                  int.TryParse(Console.ReadLine(), out numberOfQuestions);
              } while (numberOfQuestions % 10 != 0);
  
              int score = GetResult(numberOfQuestions, userDifficulty);
              Console.WriteLine($"You got a score of {score} out of {numberOfQuestions}");
          }
      }
  }
  </code></pre>