Hello!!!!
Kindly help me in resolving error in my this program.  
1   The name 'yes' does not exist in the current context    E:\Lectures and books\C SHARP\Projects\enum.cs  85  20  EnumMonth


Error   
2   The name 'yes' does not exist in the current context    E:\Lectures and books\C SHARP\Projects\enum.cs  85  34  EnumMonth
Error



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EnumMonth
{
    class Program
    {
        static void Main(string[] args)
        {
            do
            {
                int mon;
                Console.WriteLine("\n\t\t==============================================");
                Console.WriteLine("\n\t\tPlease Enter The Month Number to Get the MONTH");
                Console.WriteLine("\n\t\t==============================================");
                mon = int.Parse(Console.ReadLine());
                switch (mon)
                {
                    case 1:
                        string a = Enum.GetName(typeof(months), 0);
                        Console.WriteLine("\t\t{0}", a);
                        break;

                    case 2:
                        string b = Enum.GetName(typeof(months), 1);
                        Console.WriteLine("\t\t{0}", b);
                        break;

                    case 3:
                        string c = Enum.GetName(typeof(months), 2);
                        Console.WriteLine("\t\t{0}", c);
                        break;

                    case 4:
                        string d = Enum.GetName(typeof(months), 3);
                        Console.WriteLine("\t\t{0}", d);
                        break;

                    case 5:
                        string e = Enum.GetName(typeof(months), 4);
                        Console.WriteLine("\t\t{0}", e);
                        break;

                    case 6:
                        string f = Enum.GetName(typeof(months), 5);
                        Console.WriteLine("\t\t{0}", f);
                        break;

                    case 7:
                        string g = Enum.GetName(typeof(months), 6);
                        Console.WriteLine("\t\t{0}", g);
                        break;

                    case 8:
                        string h = Enum.GetName(typeof(months), 7);
                        Console.WriteLine("\t\t{0}", h);
                        break;

                    case 9:
                        string i = Enum.GetName(typeof(months), 8);
                        Console.WriteLine("\t\t{0}", i);
                        break;

                    case 10:
                        string j = Enum.GetName(typeof(months), 9);
                        Console.WriteLine("\t\t{0}", j);
                        break;

                    case 11:
                        string k = Enum.GetName(typeof(months), 10);
                        Console.WriteLine("\t\t{0}", k);
                        break;

                    case 12:
                        string l = Enum.GetName(typeof(months), 11);
                        Console.WriteLine("\t\t{0}", l);
                        break;

                }
                Console.WriteLine("Press Y to run again");
                string yes = Console.ReadLine();
            }
            while (yes == 'Y' || yes == 'y');
            Console.ReadLine();
        }
    }
    enum months
    {
        january,
        february,
        march,
        april,
        may,
        june,
        july,
        august,
        september,
        october,
        november,
        december

    }
}

Try declaring 'yes' before the do block.

the code :

 Console.WriteLine("Press Y to run again");
string yes = Console.ReadLine();

is within "do" loop so is considered as local variable for block inside "do" loop and hence would not be recognized outside do loop.Try doing it as tinstaafl sugested.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.